I am using the following code to create a Custom Post Type and a Custom Taxonomy:
// 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' => '',
)
));
}
Everything appears to be working on the surface, I can connect a category to a resource, but when I try to query them as such:
$args = array(
'suppress_filters' => false,
'numberposts' => -1,
'post_type' => 'resource',
'category_name' => 'recruiting'
);
$the_query = new WP_Query( $args );
I don't get any results. Any ideas?