Skip Navigation

[Resolved] I need to exclude custom post types from the wordpress generated search results

This support ticket is created 2 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 2 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#2444527

I am trying to exclude custom post types from the main wordpress search. I have custom searches for custom post types with Relevanssi integration.

Following this: https://toolset.com/documentation/user-guides/creating-wordpress-custom-post-archives/

hidden link is an example of a search that includes user profile posts when I only need pages and posts to show.

When creating the WordPress Search archive, there is no way to exclude posts. I'd like to be able to edit the output like here: https://toolset.com/forums/topic/exclude-post-type-from-website-search-results-archive/#post-1138852

Thanks!

#2444633

Hello,

In your case, you can try these:
Dashboard-> Toolset-> Post Types, find and edit those specific post type, for example "user profile".
In section "Options", enable option: exclude_from_search
And test again.

More help:
https://developer.wordpress.org/reference/functions/register_post_type/#exclude_from_search
exclude_from_search
(boolean) (importance) Whether to exclude posts with this post type from front end search results.

#2445087

HI, Kind of interesting. I checked off exclude_from_search in the post type, but the posts are still included in the search results for users who are logged in. I have set Relevanssi to respect excluded posts. Is there another step?

Thank you!

#2445343

Since you are using Relevanssi integration in the search result WordPress Archive, Relevanssi plugin will take over the search result query, Toolset Blocks/Views plugin can only display the results. So the problem should be in Relevanssi plugin.

Please try these:
1) Follow our document, to exclude index of your specific post type in Relevanssi plugin side:
https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/#including-custom-posts-in-the-search
section "Including custom posts in the search"
2) Deactivate Toolset Blocks/Views plugin
3) Test the search result page again
4) If the problem still persists, it should be a problem of Relevanssi plugin, see our document:
https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/