Skip to main content
added 876 characters in body
Source Link
Chip Bennett
  • 55.1k
  • 8
  • 90
  • 170

Edit

In response to OP's answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

This is absolutely incorrect. WordPress does not automatically create custom taxonomies in this manner.

From the OP's comment:

I'm using tribe Events calendar. Check it there.

Here is the relevant PHP file from the The Events Calendar Plugin. And here are the key lines of code:

const TAXONOMY = 'tribe_events_cat';
const POSTTYPE = 'tribe_events';

...and...

register_taxonomy( self::TAXONOMY, self::POSTTYPE, array( /**snipped*/));

As suspected: the Plugin is registering a custom post type, and then registering a custom taxonomy to use for that custom post type.

Original Answer

So, you've registered a custom post type, 'tribe_events'. Two important points:

  1. By default, custom post types have no registered/supported taxonomies, including the category taxonomy.
  2. By default, the 'category' taxonomy is only registered/supported by the 'post' post-type.

In order to use the 'category' taxonomy for a custom post type, you need to do one of two things:

  1. Add 'category' to the array of taxonomies supported by the custom post type, via the 'taxonomies' parameter of the register_post_type() arguments array:

     register_post_type(
         'tribe_events',
         array(
             'taxonomies' => array( 'category' )
         )
     );
    
  2. Add 'category' taxonomy support for the custom post type, via register_taxonomy_for_object_type():

     register_taxonomy_for_object_type( 'category', 'tribe_events' );
    

Regarding your proposed "solution"

From your answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

I know of absolutely nothing in core that would auto-create a {post-type}_cat taxonomy, or that would equate a {post-type}_cat taxonomy to the category taxonomy.

What I suspect is happening here is that you've registered a custom 'tribe_events_cat' taxonomy, and then added that custom taxonomy to your custom post type, via the 'taxonomies' parameter in register_post_type().

If this is the case, then:

  1. Your question is misleading, because you indicate that you want to use the 'category' taxonomy in your query
  2. I would strongly recommend getting in the habit of referring to a custom taxonomy as a taxonomy, rather than as a category. "Category" is a taxonomy; not all taxonomies are "category".

So, you've registered a custom post type, 'tribe_events'. Two important points:

  1. By default, custom post types have no registered/supported taxonomies, including the category taxonomy.
  2. By default, the 'category' taxonomy is only registered/supported by the 'post' post-type.

In order to use the 'category' taxonomy for a custom post type, you need to do one of two things:

  1. Add 'category' to the array of taxonomies supported by the custom post type, via the 'taxonomies' parameter of the register_post_type() arguments array:

     register_post_type(
         'tribe_events',
         array(
             'taxonomies' => array( 'category' )
         )
     );
    
  2. Add 'category' taxonomy support for the custom post type, via register_taxonomy_for_object_type():

     register_taxonomy_for_object_type( 'category', 'tribe_events' );
    

Regarding your proposed "solution"

From your answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

I know of absolutely nothing in core that would auto-create a {post-type}_cat taxonomy, or that would equate a {post-type}_cat taxonomy to the category taxonomy.

What I suspect is happening here is that you've registered a custom 'tribe_events_cat' taxonomy, and then added that custom taxonomy to your custom post type, via the 'taxonomies' parameter in register_post_type().

If this is the case, then:

  1. Your question is misleading, because you indicate that you want to use the 'category' taxonomy in your query
  2. I would strongly recommend getting in the habit of referring to a custom taxonomy as a taxonomy, rather than as a category. "Category" is a taxonomy; not all taxonomies are "category".

Edit

In response to OP's answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

This is absolutely incorrect. WordPress does not automatically create custom taxonomies in this manner.

From the OP's comment:

I'm using tribe Events calendar. Check it there.

Here is the relevant PHP file from the The Events Calendar Plugin. And here are the key lines of code:

const TAXONOMY = 'tribe_events_cat';
const POSTTYPE = 'tribe_events';

...and...

register_taxonomy( self::TAXONOMY, self::POSTTYPE, array( /**snipped*/));

As suspected: the Plugin is registering a custom post type, and then registering a custom taxonomy to use for that custom post type.

Original Answer

So, you've registered a custom post type, 'tribe_events'. Two important points:

  1. By default, custom post types have no registered/supported taxonomies, including the category taxonomy.
  2. By default, the 'category' taxonomy is only registered/supported by the 'post' post-type.

In order to use the 'category' taxonomy for a custom post type, you need to do one of two things:

  1. Add 'category' to the array of taxonomies supported by the custom post type, via the 'taxonomies' parameter of the register_post_type() arguments array:

     register_post_type(
         'tribe_events',
         array(
             'taxonomies' => array( 'category' )
         )
     );
    
  2. Add 'category' taxonomy support for the custom post type, via register_taxonomy_for_object_type():

     register_taxonomy_for_object_type( 'category', 'tribe_events' );
    

Regarding your proposed "solution"

From your answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

I know of absolutely nothing in core that would auto-create a {post-type}_cat taxonomy, or that would equate a {post-type}_cat taxonomy to the category taxonomy.

What I suspect is happening here is that you've registered a custom 'tribe_events_cat' taxonomy, and then added that custom taxonomy to your custom post type, via the 'taxonomies' parameter in register_post_type().

If this is the case, then:

  1. Your question is misleading, because you indicate that you want to use the 'category' taxonomy in your query
  2. I would strongly recommend getting in the habit of referring to a custom taxonomy as a taxonomy, rather than as a category. "Category" is a taxonomy; not all taxonomies are "category".
Source Link
Chip Bennett
  • 55.1k
  • 8
  • 90
  • 170

So, you've registered a custom post type, 'tribe_events'. Two important points:

  1. By default, custom post types have no registered/supported taxonomies, including the category taxonomy.
  2. By default, the 'category' taxonomy is only registered/supported by the 'post' post-type.

In order to use the 'category' taxonomy for a custom post type, you need to do one of two things:

  1. Add 'category' to the array of taxonomies supported by the custom post type, via the 'taxonomies' parameter of the register_post_type() arguments array:

     register_post_type(
         'tribe_events',
         array(
             'taxonomies' => array( 'category' )
         )
     );
    
  2. Add 'category' taxonomy support for the custom post type, via register_taxonomy_for_object_type():

     register_taxonomy_for_object_type( 'category', 'tribe_events' );
    

Regarding your proposed "solution"

From your answer:

So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value]

I know of absolutely nothing in core that would auto-create a {post-type}_cat taxonomy, or that would equate a {post-type}_cat taxonomy to the category taxonomy.

What I suspect is happening here is that you've registered a custom 'tribe_events_cat' taxonomy, and then added that custom taxonomy to your custom post type, via the 'taxonomies' parameter in register_post_type().

If this is the case, then:

  1. Your question is misleading, because you indicate that you want to use the 'category' taxonomy in your query
  2. I would strongly recommend getting in the habit of referring to a custom taxonomy as a taxonomy, rather than as a category. "Category" is a taxonomy; not all taxonomies are "category".