Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

$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
);
share|improve this answer
    
Hey @ Rajeev, thanks for the response..........How to catch the term option and pass it to the $term, do i need a JavaScript logic to do that...... –  Solomon Henry Apr 17 '12 at 4:50
    
@SolomonHenry use global $wp_query; and do print_r($wp_query) to see what it gives you.. –  Rajeev Vyas Apr 17 '12 at 6:27
    
any ideas...................... –  Solomon Henry Apr 24 '12 at 11:30
    
im getting views but no suggestions :( –  Solomon Henry Apr 25 '12 at 9:37
    
@SolomonHenry Try what was suggested in the comments. Then come back with the dumped data. –  kaiser Aug 31 '12 at 0:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.