0

I have a CPT called Clubs. To 'categorise' posts depending on if clubs are in the same league or cup competition (or neither), I also have a custom taxonomy called Opposition.

To show which clubs are in either the same competition, I am trying to create a page that functions like an Archive page where these specific Clubs posts are displayed: /clubs/opposition/

To do this, I've created a taxonomy-opposition.php template file and edited the functions.php file with the following:

// Clubs Post Type
function clubs_init() {
    $labels = array(
        'name' => 'Clubs',
        'singular_name' => 'Club',
        'add_new' => 'Add New Club',
        'add_new_item' => 'Add New Club',
        'edit_item' => 'Edit Club',
        'new_item' => 'New Club',
        'all_items' => 'All Clubs',
        'view_item' => 'View Club',
        'search_items' => 'Search Clubs',
        'not_found' =>  'No Clubs Found',
        'not_found_in_trash' => 'No Clubs found in Trash', 
        'parent_item_colon' => '',
        'menu_name' => 'Clubs',
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'has_archive' => false,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'taxonomies'  => array( 'clubs', 'opposition' ),
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'clubs',
            'with_front' => false
        ),
        'menu_icon' => 'dashicons-shield',
        'supports' => array(
        'title',
        'editor',
        'excerpt',
        'trackbacks',
        'custom-fields',
        'comments',
        'revisions',                
        'thumbnail',
        'author',
        'page-attributes'
        )
    );
    register_post_type( 'clubs', $args );
}
add_action( 'init', 'clubs_init' );

// Opposition Taxonomy
function opposition_taxonomy() {
    $labels = array(
        'search_items'      => 'Search Opposition',
        'menu_name'         => 'Opposition'
    );
    register_taxonomy( 'opposition', 'clubs', 
    array(
        'hierarchical' => true,
        'labels' => $labels,
        'query_var' => true,
        'show_admin_column' => true,
        'has_archive' => true,
        'rewrite' => array(
        'slug' => 'clubs',
        'with_front' => false
    ),  
) );
}
add_action( 'init', 'opposition_taxonomy' );

The result when I try to access /clubs/opposition, though, is an Error 404. The thing baffling me is that I've done something similar for my Players CPT, creating a custom Squad taxonomy page that does display. And I've followed exactly the same steps in trying to create an Opposition page.

(I have flushed the permalinks)

I've referred to existing questions, but so far haven't found the solution:

1
  • 1
    There's nothing for WordPress to display on /clubs/opposition. WordPress only lists posts on archives, and /clubs/opposition isn't specific enough to list any posts. You need to create Opposition terms, and then you can list posts with those terms at /clubs/opposition/term-name. Jul 16, 2019 at 6:15

1 Answer 1

1

You use the same slug clubs to register your custom post type and in rewrite when you register opposition taxonomy.

Change rewrite parameter in register_taxonomy()

'rewrite' => array(
    'slug' => 'clubs/opposition',
    'with_front' => false
),

The recognizable address will be clubs/opposition/{some-term-name} and will display posts from custom category.

However, the clubs/opposition address will still not work without additional code.

1
  • That explains it! Issue now solved @nmr (and @jacob-peattie) Jul 17, 2019 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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