WP_Query::is_search()

Is the query for a search?


Return Return

(bool) Whether the query is for a search.


Top ↑

Source Source

File: wp-includes/class-wp-query.php

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


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes 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.