0

I've got a custom post type called 'Work', and one of the categories is called 'formats'

Whenever I go to the URL domain.com/archives/category/formats it doesn't show my custom post types, only the normal posts which have been catergorised 'formats'

Any ideas how to get these to show up? (I assume in a file archives-work.php )

Update: This is in my functions file.

<?php

// Custom Post Type - Work
function create_custom_post_work() {
    register_post_type( 'work',
            array(
            'labels' => array(
                    'name' => __( 'Work' ),
                    'singular_name' => __( 'Work' ),
            ),
            'public' => true,
            'has_archive' => true,
            'supports' => array(
                    'title',
                    'editor',
                    'thumbnail',
                  'custom-fields',),
         'taxonomies' => array('topics', 'category')
    ));
}
add_action( 'init', 'create_custom_post_work' );

?>
1
  • According to your sample code, your CPT isn't using the formats custom taxonomy.
    – vancoder
    Commented Mar 17, 2017 at 22:20

1 Answer 1

1

For this to work you need to register in your custom post type.

'has_archive' => true,

Or if you're using CPT UI or the like, there are settings to enable the WP Category.

Mind you, this will give it access to the global category which is also used by Posts. Otherwise you'll want to register a custom taxonomy.

For your current query:

Remove 'category' from your code above, and before you register your post type you need to register your tax. E.g:

register_taxonomy('topics', 'work', array(
    'label' => __( 'Topics' ),
));
5
  • Thanks for replying...So I've registered has_archive as true previously in my functions files for the 'Work' custom post type, but I'm still having the same issue... I'm not using CPT UI (and when I added it and turned it on none of my custom post types showed up....)
    – lycrake
    Commented Mar 17, 2017 at 18:07
  • Remove 'category' from your code above, and before you register your post type you need to register your tax. E.g: register_taxonomy('topics', 'work', array( 'label' => __( 'Topics' ), ));
    – cstls
    Commented Mar 18, 2017 at 1:47
  • Thanks for your help, I'm getting there, but not quite there yet! That created a custom taxonomy (tags) which is ok, but I want this to use the main categories in the blog. The main categories are fine, as I don't have any 'normal' blog posts. I could potentially use a custom taxonomy. The end goal is to have a page on my site which displays all the posts that have a category 'formats' (or any other category I've made.....) I will play with the custom taxonomies though.
    – lycrake
    Commented Mar 18, 2017 at 9:47
  • So I think I've cracked it. I had to create a 'category-formats.php' file and in the loop for that page I had to specify the formats category. Does that mean for all my categories I have to create seperate category-xyz.php php files? Surely there is another way that I'm missing?
    – lycrake
    Commented Mar 18, 2017 at 10:13
  • 1
    Got it! You can use single_cat_title('', false)); in the querty to pull the relevant category through and have to make sure the template hierachy is correct! Thanks for your help
    – lycrake
    Commented Mar 18, 2017 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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