Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem registering same taxonomy for different post type #6

Closed
webgrafia opened this issue Feb 2, 2017 · 4 comments
Closed

problem registering same taxonomy for different post type #6

webgrafia opened this issue Feb 2, 2017 · 4 comments

Comments

@webgrafia
Copy link

@webgrafia webgrafia commented Feb 2, 2017

Hi, I love your tool, but in this version there's a problem when registering the same custom taxonomy for different post type.
example:

  $gallery_options = [
        'has_archive' => true,
        'supports' => array("title", "editor", "author", "thumbnail"),
        'menu_position' => 5
    ];
    $gallery_names = [
        'name' => 'gallery',
        'singular' => 'Gallery',
        'plural' => 'Gallery',
        'slug' => 'gallery'
    ];
    $gallery = new PostType($gallery_names, $gallery_options);

 $marca_names = [
        'name' => 'marca',
        'singular' => 'Marca',
        'plural' => 'Marche',
        'slug' => 'marca'
    ];
    $marca_options = [
        'hierarchical' => false
    ];
$gallery->taxonomy($marca_names, $marca_options);
...
 $video = new PostType($video_names, $video_options);
 $video->taxonomy("marca");

I think the problem is in
if (taxonomy_exists($names['name'])) { $this->existingTaxonomies[] = $names['name'];

in taxonomy function, it return false.

Do you experienced the same issue?

@jjgrainger
Copy link
Owner

@jjgrainger jjgrainger commented Mar 20, 2017

Thanks for pointing this out, I'll get to fixing this as soon as I can :)

@MWDelaney
Copy link
Contributor

@MWDelaney MWDelaney commented Apr 13, 2017

I can confirm this problem --in fact trying to attach an existing taxonomy like post_tag actually removes it from posts.

@cedarstay
Copy link

@cedarstay cedarstay commented Apr 26, 2017

Can confirm that I am also experiencing this issue

@jjgrainger
Copy link
Owner

@jjgrainger jjgrainger commented Apr 28, 2017

Hi @cedarstay @MWDelaney and @webgrafia,

Just thought I'd let you know this has been fixed now. :)

The taxonomy() method was trying to use WordPress taxonomy_exists function to check if the taxonomy existed. This call was made outside of any actions, so was being run before WordPress was fully loaded. This meant the taxonomy_exists check didn't work properly.

I've updated the code so the taxonomy names and options are saved. Then the checks and registration of the taxonomies are run at the correct points in the WordPress event flow.

Thanks everyone 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants