Restrict Search Results using Search

Hi guys,

I think I already know the answer here, but is there any way I can restrict the search results from the Search Field to only show a certain custom post type?

I’ve managed to setup a blog using a custom post type with custom taxonomies but when using the Search Field it pulls results from all post types.

https://marketingforhealthpractitioners.com.au/newsletter/

From what I’ve read here, its not possible without adding some code to the functions file. Do you guys have any suggestions on what the best thread for doing this might be?

Hi @DesignMunky,

Thank you for reaching out to us. You can kind of do it through a query string looper provider. This assumes the query var is s ( s=.... )

post_type=custom_type&s={{dc:url:param key="s"}}

Another way could be by creating an Archive layout using Archive Layout Builder and provide it a condition search results is being viewed with the combination of your custom post type

Lastly you could also do this through a filter and custom code, for this we have a service called One that offers support for this.

Let me know if this helps!

Hey Nabeel,

Thanks for the helpful info - much appreciated.

I’ve been trying to get it to work by using the following conditions in my archive layout:

Post type is Newsletter Article
OR
Search Results is being viewed AND
Post type is Newsletter Article

This shows the search results on the Default Blog Layout.

If I use:
Post type is Newsletter Article
OR
Search Results is being viewed

then the layout for the search result stays in the Archive Layout like I want, but the results show all posts (not just the custom post).

Am I missing something here?

Hello @DesignMunky,

If you want to display specific custom post type on you search results page, please check this out:

Hope this helps.

Thanks I’ll definitely check it out.

So is the Archive Layout condition Search Results being Viewed suggested by Nabeel not an option that will work?

Hi @DesignMunky,

The condition in an archive layout could work. It might get complicated later on. It is best that we modify the query to prevent any issues or conflicts sooner or later.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.