WP_Query::is_search(): bool

Determines whether the query is for a search.

Return

bool Whether the query is for a search.

Source

public function is_search() {
	return (bool) $this->is_search;
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    /**
     * INCLUDE CUSTOM POST TYPES IN SEARCH RESULTS
     */
    function wpdocs_cpt_in_search( $query ) {
        if ( ! is_admin() && $query->is_main_query() ) {
            if ( $query->is_search ) {
                $query->set( 'post_type', array( 'convention' ) );
            }
        }
    }
    
    add_action( 'pre_get_posts', 'wpdocs_cpt_in_search' );

You must log in before being able to contribute a note or feedback.