Sunday, July 10, 2022
HomeWordPress DevelopmentSearch customized sort put up - WordPress Improvement Stack Trade

Search customized sort put up – WordPress Improvement Stack Trade


I wish to make my search bar on the web site present customized put up sort (programs) beside the weblog posts.

I attempted these codes However it didn’t work. The one factor that labored was the WP Prolonged Search plugin, however I wish to do it by code.

operate tg_include_custom_post_types_in_search_results( $question ) {
    if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
        $query->set( 'post_type', array( 'put up', 'programs') );
    }
}
add_action( 'pre_get_posts', 'tg_include_custom_post_types_in_search_results' );

and this

operate include_cpt_search( $question ) {
    
    if ( $query->is_search ) {
        $query->set( 'post_type', array( 'put up', 'programs', 'custom_post_type' ) );
    }
    
    return $question;
    
}
add_filter( 'pre_get_posts', 'include_cpt_search' ); 

Please advise. Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments