How to use the same bullets for custom post types and taxonomy in WordPress

I am new here and I need your help because I don’t understand how to solve this.

I need to register a new custom type of “textbooks” because I want to have a different design for them and keep them separate from the rest of the posts. I also want to organize them into categories, so I will use a taxonomy for this. I read a lot of tutorials (here and from Google) and I found many ways to do this, but the result is not the one I expected. Finally, I wrote this code in the plugin:

<?php
   /*
   Plugin Name: My Custom Post Types
   Description: A plugin for our custom post types like tutorials etc.
   */

/*====================================================
Register new custom post type - tutorials
======================================================*/
function register_my_custom_post_type_tutorials() {
  $labels = array(
    'name'               => 'Tutorials',
    'singular_name'      => 'Tutorial',
    'add_new'            => 'Add New',
    'add_new_item'       => 'Add New Tutorial',
    'edit_item'          => 'Edit Tutorial',
    'new_item'           => 'New Tutorial',
    'all_items'          => 'All Tutorials',
    'view_item'          => 'View Tutorial',
    'search_items'       => 'Search Tutorials',
    'not_found'          => 'No tutorials found',
    'not_found_in_trash' => 'No tutorials found in Trash',
    'parent_item_colon'  => '',
    'menu_name'          => 'Tutorials'
  );

  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'tutorials' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','custom-fields','page-attributes','post-formats' )
  );

  register_post_type( 'wizz-tutorials', $args );
}
add_action( 'init', 'register_my_custom_post_type_tutorials' );

/*====================================================
Register Custom Taxonomies for Tutorials - Categories
======================================================*/

add_action('init', 'register_tutorials_taxonomy');

function register_tutorials_taxonomy() {
// Add new taxonomy, make it hierarchical (like categories)
  register_taxonomy('wizz-tutorials-category',
                    'wizz-tutorials',
                     array (
                           'labels' => array (
                                              'name' => 'Tutorials Categories',
                                              'singular_name' => 'Tutorials Categories',
                                              'search_items' => 'Search Tutorials Categories',
                                              'popular_items' => 'Popular Tutorials Categories',
                                              'all_items' => 'All Tutorials Categories',
                                              'parent_item' => 'Parent Tutorials Category',
                                              'parent_item_colon' => 'Parent Tutorials Category:',
                                              'edit_item' => 'Edit Tutorials Category',
                                              'update_item' => 'Update Tutorials Category',
                                              'add_new_item' => 'Add New Tutorials Category',
                                              'new_item_name' => 'New Tutorials Category',
                                            ),
                            'hierarchical'     => true,
                            'show_ui'          => true,
                            'show_tagcloud'    => true,
                            'rewrite'          => array( 'slug' => 'tuts-category' ),
                            'public'           => true
                            )
                     );

}

?>

In the admin panel, I can now add "tutorials". I also created several categories for them (photoshop, website, etc.). The problem is that this is a bullet.

What I have at the moment:

  • mywebsite.com/tutorials/ - ( archive.php)

  • mywebsite.com/tutorials/post-name - ( single.php)

  • mywebsite.com/tuts-category/photoshop/ - ,

, - :

  • mywebsite.com/tutorials/

  • mywebsite.com/tutorials/post-name

  • mywebsite.com/tutorials/photoshop/

slug , , 'rewrite' => array( 'slug' => 'tutorials' ), 404 error.

? , ? !

+4
2

100% , , , .

. INIT, , , , hapens ( )

post type, chage has_archive:

'has_archive' => 'tutorials' // This will tell wp to use the taxonomy tutorials for the post type archive

:

'rewrite' => array(
        'slug' => 'tutorial', // Notice this will be the slug for single tutorial and can´t be the same as the archive slug, but has sence, since it´s ONE tutorial post, not ALL the tutorials, singlular, plural things in other words.
        'with_front' => true,

     ),

:

'rewrite' => array( 'slug' => 'tutorials', 'with_front' => true, 'hierarchical' => false),

, init :

flush_rewrite_rules();

, flush_rewrite_rules . , .

.

, , , , 404.

:

mywebsite.com/tutorials/ (this will use the archive or taxonomy template, ej: taxonomy-tutorials.php)

mywebsite.com/tutorial/post-name (notice what i describe about single slugs, template in use: single-tutorial.php)

mywebsite.com/tutorials/photoshop/ (this will use the archive or taxonomy template as well and also you could have a particular template only for that term)

. , , , , , wp , , , , . , - "cat-tutorials" slug, SEO.

, .

+15

. : "rewrite" => array( "slug" => "web-tutorials/%custom-taxonomy-name%" ),

custom-taxonomy-name.

,

0

All Articles