2

My custom post type is configured to use category and post_tag taxonomies. The categories and tags display fine in the admin and appear to function as expected. The categories also display fine in the UI, however when I click on a category name in the UI, the category template displays, but the WordPress loop contains no posts even though I can verify that multiple posts are associated with that category.

Perhaps my custom post type needs to be configured differently?

function create_newz() {
  $labels = array(
    'name'                => 'The Newz',
    'singular_name'       => 'Newz Item',
    'menu_name'           => 'Newz',
    'name_admin_bar'      => 'Newz',
    'add_new'             => 'Add Newz Item',
    'add_new_item'        => 'Add Newz',
    'new_item'            => 'New Newz Item',
    'edit_item'           => 'Edit Newz Item',
    'view_item'           => 'View Newz Item',
    'all_items'           => 'All Newz Items',
    'search_items'        => 'Search Newz',
    'parent_item_colon'   => 'Parent Newz:',
    'not_found'           => 'No Newz Items found.',
    'not_found_in_trash'  => 'No Newz Items found in Trash.'
  );

  $args = array(
    'labels'              => $labels,
    'public'              => true,
    'publicly_queryable'  => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'menu_position'       => 5,
    'menu_icon'           => 'dashicons-id-alt',
    'query_var'           => true,
    'rewrite'             => array('slug' => 'newz'),
    'capability_type'     => 'post',
    'has_archive'         => true,
    'hierachical'         => false,
    'supports'            => array('title','editor', 'custom-fields', 'thumbnail'),
    'taxonomies' => array('category', 'post_tag')
  );
  register_post_type('newz', $args);

}
2

By default, WordPress will only include the post post type within the post_tag and category taxonomy archives.

Use this snippet to add newz posts to the post_tag and category taxonomy archives:

add_filter( 'pre_get_posts', 'wpse_newz_taxonomy_archives' );
function wpse_newz_taxonomy_archives( $query ) {
  if ( $query->is_main_query() && ( is_category() || is_tag() ) ) {
        $query->set( 'post_type', array( 'post', 'newz' ) );
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.