jjgrainger/wp-custom-post-type-class

Custom taxonomy not registering

bynicolas opened this issue · 2 comments

I can't seem to be able to register a custom tax to my CPT. Here my code in the simplest form possible, but yet it won't show up in the admin screen.

There was a similar issue about a year ago, but I tripled checked my code and all seems to be in order.
https://github.com/jjgrainger/wp-custom-post-type-class/issues/25

What am I not seeing?

$movies = new CPT( array(
    'post_type_name'    => 'movie',
    'singular'          => 'Movie',
    'plural'            => 'Movies',
    'slug'              => 'movies',
));

$movies->register_taxonomy('genre');
$movies->register_post_type();
$movies->flush();

I figured it out rereading the code again!

I wasn't using $movies->register_taxonomies(); so while the taxonomy was added, it wasn't registered!

Maybe updating the method name to add_taxonomy and updating the example code and ReadMe to better reflect what the function does because right now, register_taxonomy() is creating confusion, at least in my mind!

This is a bit strange, register_taxonomy() method should work.

Only thing I can think that might be causing an issue is where you are explicitly calling register_post_type().

The class constructor adds various methods to different hooks in WordPress with register_post_type being one of them.

There have been issues before in the past, which have been fixed, where taxonomies and post types needed to be registered in a particular order from one another to work properly.

If you remove the $movies->register_post_type(); from the code above the class should register the post type and taxonomies at the correct time.

As a note too register_taxonomies() is another method the class hooks into WordPress, so is something that is best not called explicitly.

Thanks :)