可以使用修改查询pre_get_posts
, 下面是一个示例:
<?php
function add_cpt_to_search( $wp_query ) {
if ( ! is_admin() && is_main_query() && is_search() ) {
$wp_query->set( \'post_type\', [ \'post\', \'careers\', \'page\' ] );
}
}
add_action( \'pre_get_posts\', \'add_cpt_to_search\' );
In the if-statement above there are 3 conditions: