Forums › Forums › Search & Filter Pro › Using filter on search results page after getting results with native WP search
Tagged: filter CPT, WP search
- This topic has 5 replies, 2 voices, and was last updated 4 years, 2 months ago by Trevor.
-
Anonymous(Private) September 7, 2020 at 9:58 am #258587
Hi guys,
I am using a native WP search field with a hidden input to search within a custom post type:
<input type="search" id="s" name="s" class="s" placeholder="Search" value="<?php echo esc_attr( get_search_query() ); ?>" autocomplete="off" /> <input type="hidden" name="post_type" value="watches" />
The search results page outputs the results which i echo using regular, default loop in search.php. The URL of the search results goes like this: ?s=rolex&post_type=watches
In the search results page i have created a filter to filter the search results.
The filter parameters are:
– Display results method: As an archive
– Use a custom template: true
– Filename of the custom template: search.phpThe issue is that when i hit the filter button, it redirects me to blog page with the “Nothing Found” message. Could you tell me if it is possible to filter the search results which i get from the WP search or do i need to do something else?
Thank you.
Trevor(Private) September 7, 2020 at 11:15 am #258591You can use a wordpress rewrite to point a theme global search to our form. There is an example here (the site shown uses a slug name for the search results page, which looks nicer):
Here there is an example of one that doesn’t use a slug:
Note, the Search & Filter form on the results page must have a Text search field to receive the search string. You would not need/want to have the post type in the parameters, as this is specified in our form settings instead, so you should remove that from the code you already use.
Anonymous(Private) September 7, 2020 at 3:50 pm #258636Hi Trevor,
Thank you for your reply.
With the rewrite point i still get the blog page with “Nothing Found” message, but this time without getting the search results page first. What i meant is to use the filter after the search results page is generated and inside the results page.
I need the post type parameter as there are two searches what this site have. One is for blog posts and another is for the post type as the results have different styling.
Could you point me on another possible solution?
-
AuthorPosts