Custom Search Query

I’d like to set up a custom search page that does the following:

User checks off several items in a form that he’d like to see returned in his search (essentially choosing from a list of tags).

Results are returned that match all of the tags he chose (using AND not OR).

A specific example would be:

Return all posts in the category of “Area” where tags = “elementary school” AND “park”

  1. Do I need to name my search form anything in particular?
  2. On the search results page, how do I code the custom query so that it grabs all posts within the category of Area, and that have tags of all the tags the user chose in the search form?

2 s
2

1) You can use the template search.php and searchform.php as your starting points. Creating a Search Page Codex

2) As far as the custom query goes, you can use pre_get_posts hook to test if you’re on a search page, then you get $_GET your values, edit your query accordingly. Action Reference – pre_get_posts

There are tons of tutorials online and questions on this exchange to help you out. Some are Simple and others are more Complex. You’ll have to do some real research to accomplish this. Hope it helps!

Leave a Comment