Wp Search Post Type Results Page

[Solved] Wp Search Post Type Results Page | Php - Code Explorer | yomemimo.com
Question : wp search post type results page

Answered by : nasty-narwhal-kb5325yjzv1c

01
02
03
04
05
06
07
08
09
10
11
12
/**
 * This function modifies the main WordPress query to include an array of
 * post types instead of the default 'post' post type.
 *
 * @param object $query The main WordPress query.
 */
function tg_include_custom_post_types_in_search_results( $query ) {
    if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
        $query->set( 'post_type', array( 'post', 'movies', 'products', 'portfolio' ) );
    }
}
add_action( 'pre_get_posts', 'tg_include_custom_post_types_in_search_results' );

Source : https://thomasgriffin.com/how-to-include-custom-post-types-in-wordpress-search-results/ | Last Update : Fri, 29 Apr 22

Answers related to wp search post type results page

Code Explorer Popular Question For Php