3

Thanks to Otto's excellent post on advanced taxonomy queries, I (mostly) understand how to create multi-taxonomy and multi-term queries. However, what I don't know is how to build those dynamically based on user input. I'd really like to end up with something like Amazon.com has on their site, with check boxes next to the various terms for a taxonomy in the sidebar (and multiple lists of terms, each with a taxonomy heading). Something like this:

Taxonomy with list of terms and check boxes to select those terms

How should I go about building something like this? Displaying the content dynamically (content changes when a box is checked) would be great, but I'd certainly settle for having a "submit" button.

2
  • 1
    Have you looked at scribu's Multi Taxonomy Query plugin? After the internal code got merged into WP core, he now focuses on the UI.
    – Jan Fabry
    May 12, 2011 at 9:19
  • @Jan Fabry can you add this as an answer? It looks like this is what I'll end up using. May 18, 2011 at 16:20

2 Answers 2

2

I am a little fuzzy on specifics of technical side, but I think general outline would be following:

  1. Interface - you will need to either submit this as form by button or JavaScript.

  2. Query variables - you will need to register custom variable(s) via query_vars filter so your custom data is not discarded from URL.

  3. Query - modify query to make complex query, using custom data submitted.
1

submit the form with javascript when a box status is changed. Then you can use wp_query to create a new query and use tax_query to display taxonomies that is checked:

$args = array(
    ... // posttype and such
    'tax_query' => array(),
    ...// other arguments 
);
//if post is set
if(isset($_POST['cats'])){
    //pusch to array
    $args['tax_query'][] = array(
        'taxonomy' => 'the taxonomy',
        'field' => 'id', // get tax by id or slug
        'terms' => $_POST['cats'],
        'operator' => 'AND' // or you can choose 'IN'
    );
}
$new_query = new Wp_Query($args);
//start loop
while ($new_query->have_posts() ) : $new_query->the_post(); ?>

hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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