jjgrainger / wp-custom-post-type-class

A PHP Class for creating Wordpress Custom Post Types easily
MIT License
416 stars 114 forks source link

Custom Post Types: Sharing Multiple Custom Taxonomies #34

Closed eballeste closed 9 years ago

eballeste commented 9 years ago

Hi! I have an issue where I registered a custom post type with two custom taxonomies which works, but when I register a second custom post type that uses those same taxonomies, they only appear under the list view of the second custom post type but not on the actual menu nor in the edit page. Am I missing something?

This is the custom post type with the two original taxonomies: screen shot 2015-05-19 at 8 42 20 pm

And here is the second custom post type with the taxonomies only showing up in the admin list view: screen shot 2015-05-19 at 8 42 55 pm screen shot 2015-05-19 at 8 43 11 pm screen shot 2015-05-19 at 8 42 44 pm

My code:

//Litigation Graphics
$litigation = new CPT(
[
    'post_type_name' => 'litigation_graphics',
    'singular'       => 'Litigation Graphic',
    'plural'         => 'Litigation Graphics',
    'slug'           => 'litigation-graphics'
],[
    'supports'       => ['title', 'thumbnail']
]);

$litigation->register_taxonomy(
[
    'taxonomy_name'  => 'media_type',
    'singular'       => 'Media Type',
    'plural'         => 'Media Types',
    'slug'           => 'media-type'
],[
    'hierarchical'   => true
]);

$litigation->register_taxonomy(
[
    'taxonomy_name'  => 'case_type',
    'singular'       => 'Case Type',
    'plural'         => 'Case Types',
    'slug'           => 'case-type'
],[
    'hierarchical'   => true
]);

//Cases
$cases = new CPT(
[
    'post_type_name' => 'cases',
    'singular'       => 'Case',
    'plural'         => 'Cases',
    'slug'           => 'experience'
],[ 
    'supports'       => ['title', 'thumbnail', 'editor']
]);

$cases->register_taxonomy(
[
    'taxonomy_name'  => 'industry',
    'singular'       => 'Industry',
    'plural'         => 'Industries',
    'slug'           => 'industry'
],[
    'hierarchical'   => true
]);

$cases->register_taxonomy(['taxonomy_name'  => 'media_type']);
$cases->register_taxonomy(['taxonomy_name'  => 'case_type']);
eballeste commented 9 years ago

This worked:

//Cases
$cases = new CPT(
[
    'post_type_name' => 'cases',
    'singular'       => 'Case',
    'plural'         => 'Cases',
    'slug'           => 'experience'
],[ 
    'supports'       => ['title', 'thumbnail', 'editor'],
    'taxonomies'     => ['media_type', 'case_type']
]);
jjgrainger commented 9 years ago

The update in v1.3.1, where taxonomies are registered before the post type, seems to have broken this.

I'll have to look into this,

Thanks :)