Skip Navigation

[Resolved] custom post types do not appear in search results

This support ticket is created 5 years, 9 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 5 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1229559

I am trying to:include a toolset custom post type in search results

Link to a page where the issue can be seen:hidden link

I expected to see:this page should display a hotel custom post type result for Saneeva Jani

Instead, I got: other pages that contained the word Jani but not the custom post type for that hotel.

It is my intention to turn on relevanssi also, once the above issue is resolved.

Thanks

#1229569

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

Thank you for contacting our support forum.

Actually the wordpress default search on the frontend does not automatically add the custom post types to the search, so you will need to use the relevanssi plugin so that they can be indexed for the default search.

Please let me know if this helps.

Thanks,
Shane

#1229609

Shane

no that doesn't help, sorry.
Why don't you login activate relevanssi and you'll see there are no custom post types in the search results.

Mark

#1229616

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

Lets try this using a different method since relevanssi isn't working out. You can add the following code to our Toolset custom code section. This can be found in Toolset -> Settings -> Custom Code where you need to add it to the file and activate it.

function cus_post_search_filter($query) {
    if (!$query->is_admin && $query->is_search) {
        $query->set('post_type', array('post', 'page', 'book'));
    }
    return $query;
}
add_filter('pre_get_posts', 'cus_post_search_filter');

To add you post types to the search just add the slugs to it.
Example

array('post', 'post-type-slug2', 'post-type-slug1','post-type-slug3')

This will add your respective post types to the search.

Please let me know if this helps.
Thanks,
Shane