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”
- Do I need to name my search form anything in particular?
- 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?
1) You can use the template
search.php
andsearchform.php
as your starting points. Creating a Search Page Codex2) 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_postsThere 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!
In order to make a custom search you are going to want these inputs in your html. You can use the name and value attributes to pass to your URL.
Then in your scripts file you are going to want to build your URL.
Then you can add this filter to your funcitons.php. This will grab the variables from the URL and pass them to the search query.
The results should load on your search.php