1

I'm trying to achieve an URL structure that implies sharing the same slug ("videos") for a Custom Post Type (video), and two Taxonomies (video_category, video_tag), in order to have:

Page:
/videos

Taxonomy (video_category):
/videos/tutorials
/videos/seminars
/videos/demos

Taxonomy (video_tag):
/videos/boxing
/videos/kickboxing
/videos/mma

Custom Post Type:
/videos/video-name-1
/videos/video-name-2
/videos/video-name-3

Of course, there are conflicts happening because of the same slug. I do know I need to Flush Rewrites by going to Settings > Permalinks, and "Save".

I suppose I need a "rewrite rule", and there are so many examples out there, but I don't seem to find an easy and clean solution at this moment. So any help is welcomed. (No Plugins suggestions, thanks).

Here's the code (shortened) for the CPT and Taxonomies:

// Post Type: Video
// --------------------------------------------------------------------
function video_post_type() {

    $labels = array(
        'name'         => _x( 'Videos', 'Post Type General Name', 'manonuda' ),
        'singular_name'     => _x( 'Video', 'Post Type Singular Name', 'manonuda' ),
    );
    
    $args = array(
        'label'         => __( 'videos', 'manonuda' ),
        'description'      => __( 'Manonuda Videos', 'manonuda' ),
        'labels'        => $labels,
        'supports'       => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
        'taxonomies'      => array( 'video_category', 'video_tag' ),
        'hierarchical'    => false,
        'public'       => true,
        'rewrite' => array(
        'slug' => 'videos',
            'with_front' => false
        )
    );
    
    register_post_type( 'video', $args );

}
add_action( 'init', 'video_post_type', 0 );


// Taxonomy: Video Category
// --------------------------------------------------------------------
function video_category_taxonomy() {

    $labels = array(
        'name'            => _x( 'Video Categories', 'Taxonomy General Name', 'manonuda' ),
        'singular_name'     => _x( 'Video Category', 'Taxonomy Singular Name', 'manonuda' ),
    );
    $args = array(
        'labels'           => $labels,
        'hierarchical'       => true,
        'public'           => true,
      'query_var' => true,
      'rewrite' => array(
        'slug' => 'videos',
        'with_front' => false
      )
    );
    
    register_taxonomy( 'video_category', array( 'video' ), $args );

}
add_action( 'init', 'video_category_taxonomy', 0 );


// Taxonomy: Video Tag
// --------------------------------------------------------------------
function video_tag_taxonomy() {

    $labels = array(
        'name'            => _x( 'Video Tags', 'Taxonomy General Name', 'manonuda' ),
        'singular_name'    => _x( 'Video Tag', 'Taxonomy Singular Name', 'manonuda' ),
    );
    $args = array(
        'hierarchical'      => false,
        'public'           => true,
        'query_var' => true,
        'rewrite' => array(
        'slug' => 'videos',
        'with_front' => false
      )
    );
    
    register_taxonomy( 'video_tag', array( 'video' ), $args );

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.