我使用以下代码创建自定义帖子类型和自定义分类法:
// Register Post Type
add_action( \'init\', \'cptui_register_my_cpt_resource\' );
function cptui_register_my_cpt_resource() {
register_post_type( \'resource\', array(
\'label\' => \'Resources\',
\'description\' => \'\',
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
\'map_meta_cap\' => true,
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'resource\', \'with_front\' => true),
\'query_var\' => true,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'thumbnail\', \'author\', \'page-attributes\',\' post-formats\' ),
\'labels\' => array (
\'name\' => \'Resources\',
\'singular_name\' => \'Resource\',
\'menu_name\' => \'Resources\',
\'add_new\' => \'Add Resource\',
\'add_new_item\' => \'Add New Resource\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit Resource\',
\'new_item\' => \'New Resource\',
\'view\' => \'View Resource\',
\'view_item\' => \'View Resource\',
\'search_items\' => \'Search Resources\',
\'not_found\' => \'No Resources Found\',
\'not_found_in_trash\' => \'No Resources Found in Trash\',
\'parent\' => \'Parent Resource\',
)
));
}
// Register Taxonomy
add_action( \'init\', \'cptui_register_my_taxes_resource_categories\' );
function cptui_register_my_taxes_resource_categories() {
register_taxonomy( \'resource categories\', array( 0 => \'resource\' ), array(
\'hierarchical\' => true,
\'label\' => \'Resource Categories\',
\'show_ui\' => true,
\'query_var\' => true,
\'show_admin_column\' => false,
\'labels\' => array (
\'search_items\' => \'Resource Category\',
\'popular_items\' => \'\',
\'all_items\' => \'\',
\'parent_item\' => \'\',
\'parent_item_colon\' => \'\',
\'edit_item\' => \'\',
\'update_item\' => \'\',
\'add_new_item\' => \'\',
\'new_item_name\' => \'\',
\'separate_items_with_commas\' => \'\',
\'add_or_remove_items\' => \'\',
\'choose_from_most_used\' => \'\',
)
));
}
一切似乎都在表面上运行,我可以将一个类别连接到一个资源,但当我尝试这样查询它们时:
$args = array(
\'suppress_filters\' => false,
\'numberposts\' => -1,
\'post_type\' => \'resource\',
\'category_name\' => \'recruiting\'
);
$the_query = new WP_Query( $args );
我没有得到任何结果。有什么想法吗?