WP_Query::is_search(): bool

Determines whether the query is for a search.


Return

bool Whether the query is for a search.


Top ↑

Source

File: wp-includes/class-wp-query.php. View all references

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


Top ↑

Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by lazhar007
    /**
     * 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.