custom taxonomy - Unable to display the post titles in a drop down

I have post type Dealers and a taxonomy Manufacturer i have a list of manufacturers and relevant posts. Im trying to dis

I have post type Dealers and a taxonomy Manufacturer i have a list of manufacturers and relevant posts. Im trying to display the list of manufacturers in a drop down, when a manufacturer is selected say: Audi and based on the selection i have to populate the post titles related to Audi in another drop down. below is the code

<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 logic

<?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>
    */
?>

What i am getting is if i un-comment the comment tags in getpost.php file im getting the error as Fatal error: Class 'WP_Query' not found in C:\xampp\htdocs\cah-new\wp-content\themes\carandhalf\includes\getpost.php on line 14 but im successfully echoing the selected option echo $term;

if there is still wrong in my logic do pint-it-out, kindly help me....

I have post type Dealers and a taxonomy Manufacturer i have a list of manufacturers and relevant posts. Im trying to display the list of manufacturers in a drop down, when a manufacturer is selected say: Audi and based on the selection i have to populate the post titles related to Audi in another drop down. below is the code

<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 logic

<?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>
    */
?>

What i am getting is if i un-comment the comment tags in getpost.php file im getting the error as Fatal error: Class 'WP_Query' not found in C:\xampp\htdocs\cah-new\wp-content\themes\carandhalf\includes\getpost.php on line 14 but im successfully echoing the selected option echo $term;

if there is still wrong in my logic do pint-it-out, kindly help me....

Share Improve this question edited Apr 24, 2012 at 7:36 Solomon Henry asked Apr 16, 2012 at 13:36 Solomon HenrySolomon Henry 893 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
$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
);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627476a4636896.html

相关推荐

  • custom taxonomy - Unable to display the post titles in a drop down

    I have post type Dealers and a taxonomy Manufacturer i have a list of manufacturers and relevant posts. Im trying to dis

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信