I created a custom post type "media" and added several posts with different categories assigned (Press Release, Media Resource, News Article)
On my Media archive template I use WP_Query to try and display the most recent 3 of each. Instead each section shows the most recent of ANY of them.
Also, on the "archive" page I see my categories listed but when I click on any of them they say "no posts", so my CPT is simply not playing well with the categories, any help appreciated!
function create_post_type_media()
{
register_taxonomy_for_object_type('category', 'media'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'media');
register_post_type('media', // Register Custom Post Type
array(
'labels' => array(
'name' => __('Media Posts', 'html5blank'), // Rename these to suit
'singular_name' => __('Media Post', 'html5blank'),
'add_new' => __('Add New', 'html5blank'),
'add_new_item' => __('Add New Media Post', 'html5blank'),
'edit' => __('Edit', 'html5blank'),
'edit_item' => __('Edit Media Post', 'html5blank'),
'new_item' => __('New Media Post', 'html5blank'),
'view' => __('View Media Post', 'html5blank'),
'view_item' => __('View Media Post', 'html5blank'),
'search_items' => __('Search Media Post', 'html5blank'),
'not_found' => __('No Media Posts found', 'html5blank'),
'not_found_in_trash' => __('No Media Posts found in Trash', 'html5blank')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
), // Go to Dashboard Custom HTML5 Blank post for supports
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
)
));
}
add_action('init', 'create_post_type_media');
Here is one of my WP_Query for reference:
$args = array(
'showposts' => 3,
'post_type' => 'media',
'category_name' => 'media-resource',
);
$query = new WP_Query( $args );
if ($query->have_posts()) : ?>