Question

I'm in the process of building out a search page to perform a query on a custom post type and its associated meta and taxonomy. Eventually, I would it to query multiple taxonomies as well as compare values to those in the meta (ie - find posts with foo between X and Y).

I have a pretty good understanding of the query function, thanks to the posts by Otto and Scribu. The problem is I'm struggling to figure out how to pass the variables in via a form. My first attempt was to try the method recommended in this post, but I'm not returning any results (address bar shows: http://sitename.com/?brand=22. Here's my first attempt ("brand" is one of my taxonomy names):

<form action="<?php echo home_url('/'); ?>" method="get">
    <p><?php wp_dropdown_categories('taxonomy=brand&name=brand'); ?></p>
    <p><input type="submit" value="Search!" /></p>
</form>

Will a simple HTML form such as this suffice? Or should I be building a function in my functions.php file?

My second attempt was to incorporate a function:

<?php
function get_terms_dropdown($taxonomies, $args){
    $myterms = get_terms($taxonomies, $args);
    $output ='<select multiple="yes" size="3" name="'.$taxonomies.'">';
    foreach($myterms as $term){
        $root_url = get_bloginfo('url');
        $term_taxonomy=$term->taxonomy;
        $term_slug=$term->slug;
        $term_name =$term->name;
        #$link = $root_url.'/'.$term_taxonomy.'/'.$term_slug;
        #$link = $term_taxonomy;
        $output .="<option value='".$term_name."'>".$term_name."</option>";
    }
    $output .="</select>";
return $output;
}
$args = array('orderby'=>'count','hide_empty'=>true);
?>


<form role="search" method="get" id="searchform" action="<?php bloginfo('home'); ?>">
<?php echo get_terms_dropdown(array('brand'), $args); ?>
<input type="submit" id="searchsubmit" value="Search" />
</form>

But again, I'm not able to submit the form/generate results.

Am I on the right track here? Any suggestions are appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top