Share Tags Between Custom Posts in Admin

Let’s say I have several custom post types that all have support for post tags. Since these custom post types will all be tagged with mostly the same keywords, I’d like to know if there is a way to share the commonly used tags between the custom post types.

So if I were to browse a post edit screen for Custom Post Type 1, it would also show Custom Post Type 2 tags inside the metabox. This would be a time-saver.

Related posts

Leave a Reply

1 comment

  1. When you register_taxonomy you can simply add an array of post_types to $object_type parameter.

    From WordPress-codex:

    (array/string) (required) Name of the object type for the taxonomy
    object. Object-types can be built-in objects (see below) or any custom
    post type that may be registered.

    So you can just add an array of post_types after you run register_taxonomy and its name in this case “genre”.
    See code below:

    //hook into the init action and call create_book_taxonomies when it fires
    add_action( 'init', 'create_book_taxonomies', 0 );
    
    //create genres for the post_types post and page
    function create_book_taxonomies() {
    
      $labels = array(
        'name' => _x( 'Genres', 'taxonomy general name' ),
        'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Genres' ),
        'all_items' => __( 'All Genres' ),
        'parent_item' => __( 'Parent Genre' ),
        'parent_item_colon' => __( 'Parent Genre:' ),
        'edit_item' => __( 'Edit Genre' ), 
        'update_item' => __( 'Update Genre' ),
        'add_new_item' => __( 'Add New Genre' ),
        'new_item_name' => __( 'New Genre Name' ),
        'menu_name' => __( 'Genre' ),
      );    
    
      register_taxonomy(
        'genre',
        array('post', 'page'), // add your post_types here
        array(
            'hierarchical' => false,
            'labels' => $labels,
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'genre' ),
      ));
    }
    

    Then you share the same data on dose post_types.