我有帖子类型Dealers 和分类法Manufacturer 我有一份制造商名单和相关帖子。我试图在下拉列表中显示制造商列表,当选择一个制造商时,比如:奥迪,根据选择,我必须在另一个下拉列表中填充与奥迪相关的帖子标题。下面是代码
<script type="text/javascript">
function showPost(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","<?php echo get_bloginfo(\'template_url\')?>/includes/getpost.php?q="+str,true);
xmlhttp.send();
}
</script>
<form role="search" method="get" id="searchform" action="">
<div>
<?php
function get_terms_dropdown($taxonomies, $args)
{
$myterms = get_terms($taxonomies, $args);
$optionname = "optionname";
$emptyvalue = "";
$output ="<select name=\'selectTax\' onchange=\'showPost(this.value)\'><option selected=\'".$selected."\' value=\'".$emptyvalue."\'>Select a Category</option>\'";
foreach($myterms as $term){
$term_taxonomy=$term->manufacturer; //CHANGE Here
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option name=\'".$link."\' value=\'".$link."\'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}
$taxonomies = array(\'manufacturer\'); // CHANGE Here
$args = array(\'order\'=>\'ASC\',\'hide_empty\'=>true);
echo get_terms_dropdown($taxonomies, $args); //call to the function
?>
<!-- second drop down logic -->
<br />
<div id="txtHint"><b></b></div>
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
getpost。php逻辑
<?php
$term=$_GET[\'q\'];
echo $term;
/*$args=array(
\'post_type\' => \'dealers\',
\'taxonomy\' =>\'manufacturer\',
\'term\' => $term,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'caller_get_posts\'=> 1,
\'orderby\' => \'ID\',
);
//$my_query = null;
$my_query = new WP_Query($args);
?>
<select name="menu">
<option name="list">Select a Post</option>
<?php
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option>
<?php
endwhile;
?>
</select>
*/
?>
我得到的是,如果我在getpost中取消注释注释标记。php文件im获取错误为
Fatal error: Class \'WP_Query\' not found in C:\\xampp\\htdocs\\cah-new\\wp-content\\themes\\carandhalf\\includes\\getpost.php on line 14但我成功地回显了所选选项
echo $term;如果我的逻辑仍有错误,请把它品脱出来,请帮助我。。。。