• First off, hope I have this in the right section.

    I created a new taxonomy called description. I want to display this on pages, but only certain pages. I am not talking about on the site itself, but in the backend where you edit the pages. I am looking to only have the taxonomy box appear on certain pages. Is it possible?

    Some options that would work.

    1. Have it only displayed on pages that have a specific page template assigned.
    2. Have it displayed on pages that are set as a child of another page. For example, I have a page called clients and have created a dozen pages as children of clients. Can I have this new taxonomy only display on those child pages?

    I thought of using a custom post type, but unfortunately it would not work for this particular site.

    Any help would be great, thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter adam533

    (@adam533)

    Anyone? Hoping to get this accomplished for a current project and can’t seem to find an answer.

    Adam, did you get any resolution on this?

    Thread Starter adam533

    (@adam533)

    Nope, never did figure this out but would still like to know.

    I would also very much like to do this. I know Advanced Custom Fields lets you specify to only show certain options if parent page equals an id – I wonder if that can be used somehow.

    So, I’ve got it to where I can remove it from all pages, now I need to figure out how to adjust the ‘page’ value to only be a certain section of pages. I’m going to assume I’ll need to query the DB but I’m not sure how.

    Perhaps I won’t be able to use the remove_meta_box function at all that way, but fingers are crossed.

    // Remove taxonomy boxes from certain pages
    function gg_no_more_tax() {
      remove_meta_box('agegroupdiv','page','normal');
    }
    
    add_action('admin_init','gg_no_more_tax');

    Well, a lot of hair pulling occurred here (absolute amateur when it comes to this stuff), but I’ve got a solution that works for me.

    I’ve got it set up so that my Custom Taxonomies only show on pages that are a descendant of a certain ancestor.

    // Remove taxonomy boxes from certain pages
    function gg_no_more_tax() {
        $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
        $parent = get_post_ancestors($post_id);
      	if(!in_array('4',$parent)) {
      		remove_meta_box('agegroupdiv','page','normal');
      		remove_meta_box('venuediv','page','normal');
      	}
    }
    
    add_action('admin_init','gg_no_more_tax');

    A rundown of what’s happening:

    • Get id of current page
    • Get ancestors of current page
    • Check if a certain page is contained in the array (in my case I was looking for a page with the id of 4)
    • Remove meta boxes if not in that tree

    Hope this helps!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display custom taxonomy box on specific pages in WordPress admin area’ is closed to new replies.