Site logo

Archived topic

How do I make my CPT searchable on the front end?

1 reply · Started by Heath on May 26, 2022

Viewing posts 1–2 of 2

I am lost on the final steps of seeing how I can make the CPT player profiles searchable on the front end and include them in the menu.

Hi there,

to include the CPT in the search results, add this PHP Snippet to your site:

function include_cpt_search( $query ) {
    if ( $query->is_search ) {
	$query->set( 'post_type', array( 'post', 'page', 'custom_post_type' ) );
    }
    return $query;
}
add_filter( 'pre_get_posts', 'include_cpt_search' );

Where you see custom_post_type - replace that with the name of your CPT.

For the menus - if you're not seeing them in Appearance > Menus, click the Screen Options tab ( top right corner ) and make sure the post type is checked.

This archived topic is closed to new replies.