I need to display results of three different search queries on one page. More precisely, there is a searchbox on my page where a user enters a search phrase. Once the search phrase is submitted, I need to take the generated WP search query and modify it to build three different custom queries.

The results of these three queries will be then displayed on a page in separate blocks.

So for example, a user searches for the ‘Honda’ phrase. Then he gets the results of three search queries:

  1. ‘Honda’ in custom posts called ‘Cars’,
  2. ‘Honda’ in custom posts called ‘Motorbikes’,
  3. ‘Honda’ in custom posts called ‘Tracks’,

I know that the simplest way to modify a WP search query is to use the pre_get_posts action hook, but I’m not sure how I can use it to create three separate queries.

Your advice will be much appreciated.

1 Answer
1

You can use pre_get_posts to modify the main query, but you will need to create new queries for the other searches. Use get_query_var('s') to get the search terms and create new WP_Query objects to perform your search.

Without more information it is hard to provide much more detail to the answer.

Leave a Reply

Your email address will not be published. Required fields are marked *