Does anyone know how to alter WordPress search to filter by query vars? The query vars are custom fields. For example, I have a custom post type “books” and I want users to be able to search based on the “book_author” custom field.
The url after I hit the search button looks like this:
?search_filter=book_author&s=tolkien&post_type=book
Any help would be greatly appreciated.
You will want to do something like this within your PHP code on a search page.
of course you may want to look at securing the code against SQL injection etc etc but this gives you a starting point into creating a page which will do what you want.
I would recommend reading more about
WP_Query
, especially the parts about order by and parameters.