WordPress.org

Forums

[resolved] custom taxonomies not linking in dashboard (2 posts)

  1. martiniboy
    Member
    Posted 4 years ago #

    I have created new taxonomies for my custom posts and they work fine within the post and displaying as I wanted on the site, but when I click on the taxonomy in the sidebar of the dashboard it takes me to a 404 page. My code for the custom posts and post taxonomies are below

    register_post_type('haircare', array(
    	'labels' => array('name' => 'Haircare',
    	'singular_name' => 'Haircare',
    	'add_new' => 'Add New Post',
    	'add_new_item' => 'Add New Post',
    	'edit' => 'Edit Post',
    	'edit_item' => 'Edit Post',
    	'new_item' => 'Add new Post',
    	'view' => 'View Post',
    	'view_item' => 'View Post',
    	'search_items' => 'Search Posts',
    	'not_found' => 'Post Not Found',
    	'not_found_in_trash' => 'No Posts in Trash',
    	),'public' => true,
    	'show_ui' => true,
    	 'menu_position' => 5,
    	'capability_type' => 'post',
    	'hierarchical' => false,
    	'rewrite' => array("slug" => "haircare"), // Permalinks format
    	'query_var' => false,
    	'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
    ));
    register_post_type('latestnews', array(
    	'labels' => array('name' => 'Latest News',
    	'singular_name' => 'Latest News',
    	'add_new' => 'Add New Post',
    	'add_new_item' => 'Add New Post',
    	'edit' => 'Edit Post',
    	'edit_item' => 'Edit Post',
    	'new_item' => 'Add new Post',
    	'view' => 'View Post',
    	'view_item' => 'View Post',
    	'search_items' => 'Search Posts',
    	'not_found' => 'Post Not Found',
    	'not_found_in_trash' => 'No Posts in Trash',
    	),'public' => true,
    	'show_ui' => true,
    	 'menu_position' => 3,
    	'capability_type' => 'post',
    	'hierarchical' => false,
    	'rewrite' => array("slug" => "whatsnew"), // Permalinks format
    	'query_var' => false,
    	'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
    ));
    
    add_action( 'init', 'register_my_taxonomies', 0 );
    
    function register_my_taxonomies() {
    
    	register_taxonomy(
    		'Haircare-Category',
    		array( 'haircare' ),
    		array(
    			'public' => true,
    			'labels' => array(
    				'name' => __( 'Categories' ),
    				'singular_name' => __( 'Category' ),
    
    			),
    			'hierarchical' => true,
    			'show_ui' => true,
    'query_var' => true,
    'rewrite' => true 
    
    		)
    	);
    	register_taxonomy(
    		'LatestNewsCategory',
    		array( 'latestnews' ),
    		array(
    			'public' => true,
    			'labels' => array(
    				'name' => __( 'Categories' ),
    				'singular_name' => __( 'Category' ),
    
    			),
    			'hierarchical' => true,
    			'show_ui' => true,
    'query_var' => true,
    'rewrite' => true 
    
    		)
    	);
    	register_taxonomy(
    		'LatestnewsTags',
    		array( 'latestnews' ),
    		array(
    			'public' => true,
    			'labels' => array(
    				'name' => __( 'Post Tags' ),
    				'singular_name' => __( 'Tags' ),
    
    			),
    			'hierarchical' => false,
    			'show_ui' => true,
    'query_var' => true,
    'rewrite' => true 
    
    		)
    	);
    }
    function ftc_flush_rewrites() {
     global $wp_rewrite;
     $wp_rewrite->flush_rules();
    }
    
    function ftc_add_rewrites() {
     global $wp_rewrite;
     $ftc_new_non_wp_rules = array(
    	'find/(this)' => '/addit.php?here=$1',
     );
    
     $wp_rewrite->non_wp_rules = $ftc_new_non_wp_rules + $wp_rewrite->non_wp_rules;
    }
    
    add_action('generate_rewrite_rules', 'ftc_add_rewrites');
    add_action('admin_init', 'ftc_flush_rewrites');

    At the bottom is a function to allow permalinks for the custom posts

  2. martiniboy
    Member
    Posted 4 years ago #

    Sorted it, I should not have used uppercase letters in registering the taxonomy

Topic Closed

This topic has been closed to new replies.

About this Topic