Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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