简体   繁体   中英

WordPress Taxonomy Page Not Working

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM