WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?

I’m trying to understand how WordPress search works. I haven’t found much info on the Codex. Arguably, search is not the best WP feature. Even WordPress.org uses Google Search.

I would like to make a custom search form to allow people search using my custom taxonomies and custom meta fields.

Read More

I’d imagine the search query would work exactly as a normal WP query, therefore a tax query and a meta query should be possible.

But how to pass the user submitted form data to a search query?

Is it possible to pass form variables to the /?s= search string in the address bar? that would make things easier…

I know there are many plugins around. Some of them quite complex. But I don’t mind learning my own way and eventually the few I tried would require some adaptation for my theme (which uses almost ten different post types and a bunch of custom taxonomies, plus loads of custom fields handled by Advanced Custom Fields plugin).

Is there any detailed article that goes in depth regarding this matter?

EDIT

I just came up with an idea, to make a form in one page, then pass the input fields variables with $GET to another page template which holds a custom WP_Query and with some IFs and ELSEs perform a custom query… Eventually I will post an answer with the code when I’m done. This is close to what I was asking, although I wanted to know if it was possible without creating a new template with a new query, oh well…

Related posts

Leave a Reply

1 comment

  1. I had the same question a couple of weeks ago. Here’s what I did to make it work for me.

    How Do I Use WP_Query to Run This Database Query as Search Result?

    If you’ll read through my answer that I posted for reference’s sake, you’ll see that I ended up adding a filter add_filter('post_request','your_function_name'); which basically allowed me to completely rewrite the mysql query that was returning results from the database based off of additional parameters that I was passing through the query string in the URL.