无法在下拉列表中显示帖子标题

时间:2012-04-16 作者:Solomon Henry

我有帖子类型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;

如果我的逻辑仍有错误,请把它品脱出来,请帮助我。。。。

1 个回复
SO网友:Rajeev Vyas
$term = \'audi\';
$term = get_term_by(\'name\',$term,\'your taxonomy\');
$args=array(
  \'post_type\' => \'gallery\',
  \'taxonomy\' =>\'images\',
  \'term\'    => $term->term_id,
  \'post_status\' => \'publish\',
  \'posts_per_page\' => -1,
  \'caller_get_posts\'=> 1
);
结束

相关推荐

如何防止家长在wp_Dropdown_Categories中被选中

我有一个父类别和几个父类别。每个groundchild都意味着以后要处理的特定方法。父母不应该被挑选出来,这仅仅意味着把孩子分组。我使用wp_dropdown_categories 具有child_of 显示下拉列表。家长的选择可能会让用户感到困惑。wp_dropdown_categories(\'child_of\'=>$ground_parent_id); 如果我添加exclude = $parent_ids, 整个下拉列表都消失了。wp_dropdown_categories(\'c