• So I registered a custom post type as well as a taxonomy for that post type. I then created a couple items in that taxonomy, but when I go to click on any of them it turns up as Invalid taxonomy.

    https://i42.tinypic.com/ncffi1.jpg

    Here is the code I use to create my custom post type + taxonomy. I have it in a plugin.

    <?php
    
    /*
    Plugin Name: Guides Post Type
    Description: Guides Post Type
    */
    
    class GW_Guides_Post_Type {
    	public function __construct() {
    		$this->register_post_type();
    		$this->metaboxes();
    		$this->guides_taxonomy();
    	}
    
    	public function guides_taxonomy() {
    		register_taxonomy(
    			'Guide Categories',
    			'gw_guides',
    			array(
    				'hierarchical' => true,
    				'label' => 'Guide Categories')
    		);
    	}
    
    	public function register_post_type() {
    		$args = array(
    			'labels' => array(
    				'name' => 'Guides',
    				'singular_name' => 'Guide',
    				'add_new' => 'Add New Guide',
    				'add_new_item' => 'Add New Guide',
    				'edit_item' => 'Edit Item',
    				'new_item' => 'Add New Item',
    				'view_item' => 'View News',
    				'search_items' => 'Search Guides',
    				'not_found' => 'No Guides Found',
    				'not_found_in_trash' => 'No Guides Found In Trash'
    			),
    			'query_var' => 'guides',
    			'rewrite' => array(
    				'slug' => 'guides',
    			),
    			'public' => true,
    			'menu_position' => 5,
    			'menu_icon' => admin_url() . 'images/media-button-other.gif',
    			'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
    			'has_archive' => true
    		);
    		register_post_type('gw_guides', $args);
    	}	
    
    	public function metaboxes() {
    		add_action('add_meta_boxes','add_guides_meta');
    
    		function add_guides_meta() {
    			// css id, title, cb funct, page, priority, cb funct arguments
    			add_meta_box('gw_guides_meta', 'Featured', 'guides_meta', 'gw_guides');
    		}
    
    		function guides_meta($post) {
    			$featured = get_post_meta($post->ID, 'featured', true);
    			?>
    				<p>
    					<label for="featured">Featured:</label>
    					<?php
    						if ($featured == "True") {
    							$checked = 'checked';
    						} else {
    							$checked = '';
    						}
    					?>
    					<input type="checkbox" name="featured" id="featured" value="True" <?php print($checked) ?> />
    					<?php echo $featured; ?>
    				</p>
    			<?php
    		}
    
    		add_action('save_post', 'save_guides_meta');
    
    		function save_guides_meta($id) {
    			update_post_meta(
    				$id,
    				'featured',
    				strip_tags($_POST['featured'])
    			);
    		}
    	}
    
    }
    
    function add_gw_guides() {
    	new GW_Guides_Post_Type();
    }
    
    add_action('init', 'add_gw_guides');
Viewing 1 replies (of 1 total)
  • Thread Starter ragnarok214

    (@ragnarok214)

    Nevermind, found the fix.

    register_taxonomy(
    			'Guide Categories',
    			'gw_guides',
    			array(
    				'hierarchical' => true,
    				'label' => 'Guide Categories')
    		);

    I needed to get rid of the space and make lowercase the ‘Guide Categories’.

Viewing 1 replies (of 1 total)
  • The topic ‘Invalid Taxonomy’ is closed to new replies.