Anyone know if I can make a checkbox-list with all terms from a taxonomy, and search for the posts belonging to the checked terms? Listing categories in the checkboxes also would be a bonus!
I built something similar for a client not too long ago. I believe your question is if it is possible -- I can definitely say yes there. How would you go about it? Well, as I don't have the code handy, I'll give you a brief run-down of the steps I went about.
- I made a custom page template and created a page to use this template. In the template, I wrote an HTML form with
method="POST"and set-up the checkboxes manually. You might be able to use
get_termsto avoid having to do it manually. I made sure the
name's of all my checkboxes were
- As I wanted to handle the form in the same page (thereby setting
action=""), I added a check for the POST variable sent by the form. If it was present, it would display the form and the search results (coming to that later). If it wasn't present, only the form would show.
- In the
else-block (the one executed if the form had been submitted) I then set-up the following arguments for the coming
$args['tax_query'] = array( 'taxonomy' => 'taxonomy_name_here', 'field' => 'slug' 'terms' => $_POST['xxxx'] );
- I then created the
WP_Queryobject and pulled the results from it.
I hope this makes sense - I went on and AJAX-ified this along with a few other modifications, however this example shows the backbone on which I built this.