Support » Plugin: Custom Post Type UI » Can't attach Taxonomy to Non-Public CPTs post types

  • I have several non-public CPTs and I’d like to attach a taxonomy to them. Unfortunately they do not display in the list of available CPTs in the taxonomy list. I had to copy the code and manually add the CPT, which worked, but now I’d like to keep them all registered in one place. Make sense? Let me know if you have any questions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Beckwith


    Hi Devin.

    Well, at first I was a bit confused by this and thought there was some complex thing about it with the non-public and taxonomies and if it was a core level thing. Then, I decided to check the CPTUI code.

    As it turns out, the part that is querying for those post types to show under the Taxonomy settings, is only querying for public ones. This is a great chance to utilize filters, which I’ve been adding a lot of for one of the next major releases, however it’s not ready for pushing out yet.

    So I’m in an odd place where I want to help you, but I’m not sure quite how to go about it yet. I can point you to the spot that sets this argument and let you default the $args variable to an empty array. The problem is that any time the plugin gets updated, you’d have to go re-do that spot, and I’d really not want to put you through that trouble for all your future post types. NOTE: The setting would be saved in the option and you wouldn’t lose previously assigned ones, unless you change that associated post types after the public = true ends up returning in some minor release. I hope that paragraph makes sense.

    Now, the other idea I had was letting you know what filter name I’d use, and help you add the apply_filters() function to your own copy. Then you could go to your theme and do an add_filter() on that and set it there, preventing future breaking once the next version comes out that has the filter natively. I’d make sure I use the exact same one I give you here.

    So, I’m just about to commit some changes I made to this spot to GitHub. I added this in place of the original $args assignment for get_post_types. I hope you’re familiar with filters and hooks 😀

    $args = apply_filters( 'cptui_attach_post_types_to_taxonomy', array( 'public' => true ), $cpt_tax_name );

    You’ll need to replace the $args variable assignment with the snippet above. It’s on line 1490 of the custom-post-type-ui.php file, for the latest version in the .org repo.

    It’ll still default to the public only if no one does anything with it, but this will allow you do the following:

    add_filter( 'cptui_attach_post_types_to_taxonomy', 'devin_nonpublic_posttypes' );
    function devin_nonpublic_posttypes( $args ) {
        return array();

    That will return just an empty array back to the filter and it’d proceed to query for all, not just the public ones.

    If you need help with any of this, do not hesitate to ask, I’m more than willing to help some more. Hopefully the filter solution is good enough for you, and since it’s getting committed already, it won’t end up changing, and I’m hoping I don’t need any more bug releases.

    WOW! Excellent response. I wouldn’t expect anything less from a WebDevStudios guy.

    I am familiar with filters/hooks, but I’m wondering… why not just display all post types public or private? It sounds like this may not be a big issue though since others don’t seem to be requesting it.

    Thanks for the excellent resolution and timely response. I need to make sure I rated this plugin 5-stars now!

    Plugin Author Michael Beckwith


    A lot of why I decided to go with the filter method.

    1. I was already planning on adding a lot of hooks for others to use anyway, you just pointed me to another spot.
    2. Most people don’t need taxonomies for the non-public post types. If they are needing them for non-public, I assume they know how to use filters.
    3. Large userbase, though nowhere near the scale of WP core. We still need to mind exactly how much changes we make to those who have already been using the plugin awhile.

    Awesome to hear that it’ll work out for you with this, and we appreciate the kind words.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can't attach Taxonomy to Non-Public CPTs post types’ is closed to new replies.