I am trying to create different post types for each section of my website, but I am stuck.
This is what I have so far:
function create_post_type() {
register_post_type( 'information',
array(
'labels' => array(
'name' => __( 'Information' ),
'singular_name' => __( 'Information' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'information'),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ),
'menu_icon' => 'dashicons-admin-post',
)
);
}
add_action( 'init', 'create_post_type' );
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'information',
'information',
array(
'hierarchical' => true,
'label' => 'Type',
'query_var' => 'information',
'rewrite' => array( 'slug' => 'type' )
)
);
}
It shows in the left sidebar on the panel Information / Add new / Type
In my website I see the post and a sidebar with all 'Types' I have registered.
I need to see, for example:
mywebsite.com/information/daily -> list all posts in information marked with daily taxonomy.
That is: mywebsite.com/customposttype/taxonomy
Actually I have a taxonomy-information.php with a loop, but it sends me to the homepage (tried taxonomy-type.php, taxonomy-information-type.php, no one works).
What am I doing wrong?
First try to re-save your permalink structure (and make sure wordpress has permissions to change .htaccess file in your root).
Second, I don't think its a very good idea to name both the post type and the taxonomy the same, and then renaming it's slug.. Is there any good reason to do so?