wp search post type results page

The solution for “wp search post type results page” can be found here. The following code will assist you in solving the problem.

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’ );

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in