我有同样的问题,使用:
function cp_init_types() {
register_post_type( \'nursing-home\',
array(
\'labels\' => array(
\'name\' => __( \'Nursing Homes\' ),
\'singular_name\' => __( \'Nursing Home\' )
),
\'public\' => true,
\'has_archive\' => true,
/*\'rewrite\' => array( \'slug\' => \'nursing-homes\', \'with_front\' => true ),
\'supports\' => array( \'title\', \'editor\', \'custom-fields\', \'thumbnail\' ),
\'publicly_queryable\' => true,
\'exclude_from_search\'=> false,
\'taxonomies\' => array(\'category\',\'post_tag\'),*/
)
);
/*register_taxonomy(\'location\',\'nursing-home\',[
\'labels\' => [
\'name\' => __(\'Locations\'),
\'singular_name\' => __(\'Location\')
],
\'public\' => true
]);*/
}
function add_my_post_types_to_query( $query ) {
if ( is_post_type_archive( "nursing-home" ) && $query->is_main_query() ) {
$query->set(\'type\',"nursing-home");
$test = $query->get(\'type\');
var_dump($test);
}
return $query;
}
add_action( \'pre_get_posts\', \'add_my_post_types_to_query\' );
add_action("init", "cp_init_types");
我添加了“pre\\u get\\u posts”操作,因为我遇到了与fightstar相同的问题。