默认情况下,Wordpress在其搜索中不包括自定义帖子类型。您可以使用pre\\u get\\u posts包含特定的CPT。在您的功能中。php:
/**
* Include custom post type in Search
*/
function cpt_include_search($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ( is_search() && $query->get( \'s\' ) ) {
// add your CPT in the array
$query->set(
\'post_type\', array(\'post\', \'page\', \'job\'),
\'meta_query\', array(
array(
\'key\' => \'job_title\',
\'value\' => \'%s\',
\'compare\' => \'LIKE\',
),
)
);
}
}
return $query;
}
add_action( \'pre_get_posts\', \'cpt_include_search\' );
另外:确保您的CPT以可搜索的方式注册。特别是这两行:
\'public\' => true,
\'publicly_queryable\' => true,