0

Hi I am building multiple sites for my work. All sites will take advantage of CPTs and Custom Taxonomies. Registered taxonomies will be handled using the Advanced Custom Fields plugin. Therefore, I would like to remove all taxonomy meta boxes from all potential sites. I know I can do this via the following:

function my_remove_meta_boxes() {
        remove_meta_box( 'tax-1div', 'CPT-1', 'side' );
        remove_meta_box( 'tax-2div', 'CPT-1', 'side' );
        remove_meta_box( 'tax-3div', 'CPT-1', 'side' );
        remove_meta_box( 'tax-4div', 'CPT-1', 'side' );
        remove_meta_box( 'tax-5div', 'CPT-1', 'side' );
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );

But this would only remove said meta boxes from defined CPT-1 and not all potential CPT combinations. To remove from all potential CPTs I would have to do this:

    function my_remove_meta_boxes() {
                remove_meta_box( 'tax-1div', 'CPT-1', 'side' );
                remove_meta_box( 'tax-2div', 'CPT-1', 'side' );
                remove_meta_box( 'tax-3div', 'CPT-1', 'side' );
                remove_meta_box( 'tax-4div', 'CPT-1', 'side' );
                remove_meta_box( 'tax-5div', 'CPT-1', 'side' );
                remove_meta_box( 'tax-1div', 'CPT-2', 'side' );             
                remove_meta_box( 'tax-2div', 'CPT-2', 'side' );
                remove_meta_box( 'tax-3div', 'CPT-2', 'side' );
                remove_meta_box( 'tax-4div', 'CPT-2', 'side' );
                remove_meta_box( 'tax-5div', 'CPT-2', 'side' );
        }
        add_action( 'admin_menu', 'my_remove_meta_boxes' );

Is there a more efficient way to do this other than by de-registering all meta boxes for all CPTs?

1 Answer 1

1

ACF is a great plugin that very well may have these as options, but you might consider registering the custom taxonomies in your theme or plugin the WordPress way.

If it's an option for you, you'd have a lot of flexibility to do a couple of things.

  1. You can register 1 taxonomy for multiple post types
  2. You can choose to hide the UI, that way you don't have to hide it later.

Here's a simple example modified from the codex for our purposes here:

add_action( 'init', 'create_wpse_tax' );

function create_wpse_tax() {
    register_taxonomy(
        'custom_tax',
        array('cpt_1','cpt_2','cpt_3'), // <- multiple post types in an array here.
        array(
            'label' => __( 'Custom Tax' ),
            'rewrite' => array( 'slug' => 'custom-tax' ),
            'hierarchical' => true,
            'show_ui' => false, // <- don't show the UI
            'hide_meta_box' => true // **EDIT** - don't show the meta box
        )
    );
}

EDIT: I just found another parameter that's not in the codex called hide_meta_box. This may be more like what you're looking for rather than completely hiding the UI. See edit in the code block above.

4
  • Cheers Jeremy, my question is how do I add terms into a taxonomy once it is hidden from the interface, as this option not only removes the meta box from the posting panel, but also removed the ability add terms via the left menu area?
    – Ollie
    Commented Sep 7, 2016 at 0:20
  • I guess that depends on what you're trying to accomplish. I assumed if you wanted to hide the UI that you had a programatic method for assigning the taxonomy, or had a custom UI approach that you were building. How were you planning on doing this without the metabox? Commented Sep 7, 2016 at 2:22
  • I was going to use the ACF taxonomy to place the meta box inline with the post. The work around I have so far has been to add the terms that are to be used, then hide the UI. The terms remain which means I can add the box in the form alone. Just means any time terms need to be added or changed, I'll need to unhide, add/change terms, then hide again.
    – Ollie
    Commented Sep 8, 2016 at 23:04
  • If you want to move the metabox, this post might help: wordpress.org/support/topic/… Commented Sep 9, 2016 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.