WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] register_post_type not showing Tags (3 posts)

  1. Doodlebee
    Member
    Posted 3 years ago #

    For the record, I've shut off all plugins and switched to the Twenty Ten theme to be sure that's not interfering, and I'm still having the issue at hand.

    I'm trying to allow the Tag interface with my new custom post type. I'm wondering if something in WP 3.0.1 has made this weird, because in 3.0, I had absolutely no problems with doing this - but now, in using 3.0.1, it ain't happening. The following is my code:

    // add the goodies
    add_action('template_redirect', 'quotes_redirect');
    
    // create the post type
    register_post_type('quotes', array(
        'labels' => array (
    	  'name' => __('Quotes'),
    	  'singular_name' => __('Quotes Management'),
    	  'add_new' => _x('Add Quote', 'quotes'),
    	  'add_new_item' => __('Add Quote'),
    	  'edit' => _x('Edit Quotes', 'quotes'),
    	  'edit_item' => __('Edit Quote'),
    	  'new_item' => __('New Quote'),
    	  'view' => _x('View Quote', 'quotes'),
    	  'view_item' => __('View Quote'),
    	  'search_items' => __('Search Quotes'),
    	  'not_found' => __('No Quotes Found'),
    	  'not_found_in_trash' => __('No Quotes found in trash.')
    	),
    	'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'post',
    	'_builtin' => false,
    	'hierarchical' => false,
    	'rewrite' => array('slug' => 'quotes'),
    	'query_var' => false,
    	'supports' => array('title', 'editor', 'excerpt'),
    	'taxonomies' => array('post_tag')
      )
    );
    
    // template selection
    function quotes_redirect() {
    	global $wp, $wp_query;
    	if ($wp->query_vars["post_type"] == "quotes") {
    		// Let's look for the property.php template file in the current theme
    		if (have_posts()) {
    			include(TEMPLATEPATH . '/quotes.php');
    			die();
    		} else {
    			$wp_query->is_404 = true;
    		}
    	}
    }

    Does anyone see anything wrong with the above that would make "tags" not appear?

    I also tried forcing it to appear by using register_taxonomy_for_object_type('post_tag', 'quotes');, but for some reason,adding this created a new box under my "Excerpt" called "Slug". So very very weird.

    I would try using "register_taxonomy()", but it seems that's for adding custom tags stuff to your custom post types - I don't want that. I want to be able to use these tags anywhere - so I just want the general addition of the tags there - which I thought using 'taxonomies' => array('post_tag'); would allow, but it's simply not working.

  2. Doodlebee
    Member
    Posted 3 years ago #

    Okay, I got it. Apparently, I needed to pop this all into a function and call on init.

    // add the goodies
    add_action('template_redirect', 'quotes_redirect');
    add_action('init', 'create_quotes_management');
    
    function create_quotes_management() {
      // create the post type
      register_post_type('quotes', array(
        'labels' => array (
    	  'name' => __('Quotes'),
    	  'singular_name' => __('Quotes Management'),
    	  'add_new' => _x('Add Quote', 'quotes'),
    	  'add_new_item' => __('Add Quote'),
    	  'edit' => _x('Edit Quotes', 'quotes'),
    	  'edit_item' => __('Edit Quote'),
    	  'new_item' => __('New Quote'),
    	  'view' => _x('View Quote', 'quotes'),
    	  'view_item' => __('View Quote'),
    	  'search_items' => __('Search Quotes'),
    	  'not_found' => __('No Quotes Found'),
    	  'not_found_in_trash' => __('No Quotes found in trash.')
    	),
        'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'post',
    	'_builtin' => false,
    	'hierarchical' => false,
    	'rewrite' => array('slug' => 'quotes'),
    	'query_var' => false,
    	'supports' => array('title', 'editor', 'excerpt'),
    	'taxonomies' => array('post_tag')
        )
      );
    }
    
    // Template selection
    function quotes_redirect() {
    	global $wp, $wp_query;
    	if ($wp->query_vars["post_type"] == "quotes") {
    		// Let's look for the property.php template file in the current theme
    		if (have_posts()) {
    			include(TEMPLATEPATH . '/quotes.php');
    			die();
    		} else {
    			$wp_query->is_404 = true;
    		}
    	}
    }

    Now it's working fine! (However, I still cannot fathom why this mysterious "Slug" thing has shown up under my Excerpt area - really weird. i can't even find it in the database anywhere to see if I can delete it that way...)

  3. Ellis Benus
    Member
    Posted 3 years ago #

    I'm trying to do this exact same thing. And I'm firing it on init inside a function...

    Any reason why neither defining an array of taxonomies inside $args for register_post_type OR register_taxonomy_for_object_type will work?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.