WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type with Tags (5 posts)

  1. Chris
    Member
    Posted 4 years ago #

    Hello, I have created a new Custom Post Type and would like to know how to use the default WordPress Tags feature with it.

    The same tag functionality that is available to the default post type.

    I created the custom post type by placing the following code in the funcitons.php file:

    add_action('init', 'movie_register');
    function movie_register() {
    	$labels = array(
    		'name' => _x('Movies', 'movie type general name'),
    		'singular_name' => _x('Movie', 'deail type singular name'),
    		'add_new' => _x('Add New', 'movie item'),
    		'add_new_item' => __('Add New Movie Item'),
    		'edit_item' => __('Edit Movie Item'),
    		'new_item' => __('New Movie Item'),
    		'view_item' => __('View Portfolio Item'),
    		'search_items' => __('Search Movie'),
    		'not_found' =>  __('Nothing found'),
    		'not_found_in_trash' => __('Nothing found in Trash'),
    		'parent_item_colon' => ''
    	);
    
    	$args = array(
    		'labels' => $labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => null
    	  ); 	
    
    	//register what we just set up above
    	register_post_type('movie', $args);
    }

    Which sets up the Movie post type in the Admin UI but does not create or display the Post Tags section.

  2. Agus Suhanto
    Member
    Posted 4 years ago #

    You can add additional entry in $args argument called 'taxonomies'. It is an array. So, your args should be like this now:

    $args = array(
    		'labels' => $labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => null,
                    'taxonomies' => array('tag')
    	  );
    
  3. Tom(dB)
    Member
    Posted 4 years ago #

    Adding 'taxonomies' => array('post_tag') worked for me.

  4. silviapfeiffer1
    Member
    Posted 4 years ago #

    When I do that, and I have the list of tags displayed at the end of the custom post, and I click on one of the tags, I get no custom posts, even though I know there are several with that tag.

  5. silviapfeiffer1
    Member
    Posted 4 years ago #

    actually, the solution to my previous problem is at http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page?replies=3 - sorry for not noticing earlier

Topic Closed

This topic has been closed to new replies.

About this Topic