Custom post type not showing in search result


I have a custom post type that I would like to be searchable (I use the relevanssi search plugin). I have the following code to add the custom post type:

add_action('init', 'eyewebz_create_post_types');
function eyewebz_create_post_types() {
        array(  'taxonomies'            => array('category'),
                'labels'                => $labels,
                'has_archive'           => true,
                'show_in_rest'          => true,
                'hierarchical'          => true,
                'public'                => true,
                'publicly_queryable'    => true,
                'supports'              => array('title', 'editor', 'post-formats', 'page-attributes', 'thumbnail', 'excerpt'),
                'menu_icon'             => 'dashicons-index-card'


This post type would need to show up in the search results, but I can’t seem to be able to do that. I have tried altering the pre_get_posts as shown below, but I still don’t get the results I need.

add_filter('pre_get_posts', 'extend_search_cpt');
function extend_search_cpt($query) 
    if($query->is_search) {
        $query->set('post_type', array('post', 'page', 'project'));

    return $query; 

If I var_dump the query after I have set the post_type, I can see that it is included in the query, but I stil don’t get any custom post types in my search result. (If I var_dump the query before, there is no sign of post_type in the query).

Any ideas what might be the issue?

, Michiel Standaert 3 years 2019-01-21T06:43:47-05:00 0 Answers 62 views 0

Leave an answer