-1

I seem to had hit a problem with using the same 'slug' => 'publications', for register_taxonomy _category and _tag. It seems only the last call register_taxonomy('publications_tag', is able to use the slug. Where as the previous call register_taxonomy('publications_category', renders a 404.

How can I use the same slug for category and tag, which I assume would then use my taxonomy-{post-type_.php template?

// Custom Post Type:

register_post_type( 'publications', $args );

    $args = array(
    'label'                 => __( 'Publication', 'text_domain' ),
    'description'           => __( 'Publications', 'text_domain' ),
    'labels'                => $labels,
    'supports'              => array(
        'title',
        'editor',
        'thumbnail',
        'excerpt',
        'revisions',
        'author',
        'post-formats',
        //'comments',
        'page-attributes'
        ),
    'taxonomies'            => array(
        'publications_category',
        'publications_tag'
        ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 20,
    'menu_icon'             => 'dashicons-align-left',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => 'publications',
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'post',
    'show_in_rest'          => true,
    'rewrite'                           => array(
    //  'slug' => 'publications',
        'with_front' => false
        ),
);

// Categorys:

register_taxonomy('publications_category', 'publications', array (
    'labels' => array (
    //
    ),
        'hierarchical' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'rewrite' => array(
            'slug' => 'publications',
            'with_front' => false ),
        'public' => true
        )
);

// Tags:

register_taxonomy('publications_tag','publications', array(
    'labels' => array (
    //
    ),
        'hierarchical' => false,
        'rewrite' => array(
            'slug' => 'publications',
            'with_front' => false ),
        )
    );
  • 1
    Short answer: you can't. WordPress determines what type of content you're querying by looking at slugs, and you cannot have two different types (i.e. two separate taxonomies) that use the exact same slug. – WebElaine Aug 9 '18 at 21:54
0

So I got this working by adding /tag or /category for the rewrite slug, rather then publications or publications/%publications_tag%. I initally thought both taxonomy types could live in the parent post-type and wordpress would figure the rest out.

Tags: 'rewrite' => array( 'slug' => 'publication/tag', 'with_front' => false ),

Looks like: domain.test/publications/tag/example-tag/ and use's the axonomy-publications_tag.php file.

Category: 'rewrite' => array( 'slug' => 'publication/category', 'with_front' => false ), Looks like: domain.test/publications/category/example-category/ and use's the axonomy-publications_category.php file.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.