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.

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!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

  1. I made a custom page template and created a page to use this template. In the template, I wrote an HTML form with action="" and method="POST" and set-up the checkboxes manually. You might be able to use get_terms to avoid having to do it manually. I made sure the name's of all my checkboxes were xxxx[].
  2. 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. if(!isset($_POST['xxxx']))
  3. In the else-block (the one executed if the form had been submitted) I then set-up the following arguments for the coming WP_Query object:
    $args['tax_query'][] = array(
    'taxonomy' => 'taxonomy_name_here',
    'field' => 'slug'
    'terms' => $_POST['xxxx']
    );
  4. I then created the WP_Query object 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.

Good luck!

share|improve this answer
    
Thank you. If you wouldn't mind, could you help me on the way with some code? I´m too much of a noob to write something like this from scratch, but I´m usually able to modify something to my liking if I have something to work with. Thanks! –  Johan Dahl Aug 31 '11 at 8:39
1  
Unnfortunately the code is licensed to my client, and I am unable to copy it or use it in any way. I suggest you instead try to repeat the steps I outlined and ask for clarification or further help as you go along! Also, if you feel your original question has been answered, it helps to have marked the answer as the accepted answer! –  Doggie52 Aug 31 '11 at 19:41
add comment

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.