Categories does not display items

Hi,

I have made some categories for my cpt, and assigned them to different posts. But in the Rest API, the post items is not included in the items:

Why does this not work, from what I have read, it is supposed to work.

Link to website: https://aamodtgroup.com/blogg/

GitHub: GitHub - aamodtgroup/aamodtgroup

HI @kasper

Can you provide the link of your REST API endpoint where these posts are included?

Hi @juanma.

Here is the blogg endpoint:

https://wp.aamodtgroup.com/wp-json/wp/v2/blogg

Hi @juanma!

Is categories not supported for CPT?

Any updates here? :slight_smile:

Hi @juanma.

I added a normal post with a category, and it showed up right away.

So it works for the regular posts, but not cpt. Does anyone know how to add support for cpt as well?

Any updates on this, I still cannot get it work…

Hi @kasper

I think that you need to a taxonomies property to your frontity.settings.js file for the CPT. Please see our docs here.

Hi @mburridge

So do I need to add categories as a taxonomy? Or do I need to make a new taxonomy and use that instead of categories?

Hi @kasper

CPTs should work with the existing taxonomies like category and tag. They don’t necessarily need a custom taxonomy to be defined.

However, when you define your CPT with register_post_type I think you need to define the taxonomy that it’s going to use in the taxonomies property in the args array. See here for more info.

Hi,

I already have registered the taxonomy.

function my_custom_post_news() {
  $labels = array(
    'name'               => _x( 'News', 'post type general name' ),
    'singular_name'      => _x( 'News', 'post type singular name' ),
    'menu_name'          => 'News'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'News about our company',
    'menu_icon'     => 'dashicons-text-page',
    'public'        => true,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'featured image', 'author' ),
    'show_in_rest'  => true,
    'has_archive'   => true,
    'taxonomies'    => array( 'category' ),
  );
  register_post_type( 'blogg', $args ); 
}
add_action( 'init', 'my_custom_post_news' );

And here you can see that I have made categories in the CPT and that they have posts in them.

Hi @kasper

Add this to the state.source section of frontity.settings.js:

"taxonomies": [
  {
    taxonomy: "category",
    endpoint: "categories",
    postTypeEndpoint: "blogg",
  },
]

See here for more info.

Hi @mburridge

That worked, thank you so much!

1 Like