[resolved] Limit search with checkboxes to specific categories/taxonomies (5 posts)

  1. code-monkey
    Posted 2 years ago #

    On my archive.php page (and search results), I'm showing all normal categories as a nice list, but I've created an additional taxonomy, and I want this to act as a 'limit search/display to...' function.

    Hence, when someone is looking in the category 'news about fish' I want them to be able to tick limit to... 'bad ideas' or 'good ideas' and so the search results/archive will only show 'news about fish' which have ALSO been tagged 'bad ideas' (or 'good ideas') if chosen.

    I'm currently using Query Multiple Taxonomies plugin but this doesn't do the job. Surely there's some core code I can use for this?

  2. bcworkz
    Posted 2 years ago #

    The WP core handles the nitty gritty of getting and dispalying search results for you, but you need to append your special criteria to the search query to get the results you want. Take a look at Creating a Search Page.

    You will need a special search form with your check boxes, of course. Then on the template that displays the results, you will need to preserve the current default query, add query arguments based on the values of your search form, and create a new WP_Query object using the modified arguments array. See the section on preserving search results in the above referenced page.

    Then just do the usual while ( $query->have_posts() ): $query->the_post(); to display the results.

  3. code-monkey
    Posted 2 years ago #

    Thanks heaps bcworkz, but the Create a search page doesn't offer much. Plus I'm not just talking about the search/search results, but also the archive.php files (various custom archive-etc.php files).

    I need to know (if there is) a specific argument that would limit any given array of posts (eg. when displaying a specific category) with an additional taxonomy checkbox.

    I don't mind if it's ajax or done with a 'submit' button. And I'm happy to pay for a few hours of coding too.

  4. bcworkz
    Posted 2 years ago #

    The process is similar for archive as for search, it's still a modified query with taxonomy arguments. Check out the WP_Query documentation for how to add taxonomy arguments.

    Please don't offer payment, I know you mean well, but it's against policy here and will get your thread shut down.

  5. code-monkey
    Posted 2 years ago #

    Aha, ok I will have more of a look. But it seems beyond me at the moment, even though I'm sure an expert could talk me through it in 5 minutes (or maybe one hour!)

    I have to get this project up and finished in less than a week. I didn't realise that about payments - I'll post on WordPress Jobs.


Topic Closed

This topic has been closed to new replies.

About this Topic