3

In my plugin I have a custom post type with a slug of 'ready-to-wear' and I have a custom taxonomy called 'seasons' associated with it.

The odd thing is that this url with query works:

http://dev.catwalkyourself.com/ready-to-wear/?seasons=autumn-winter-2012-2013-en

but the same one with custom permalink doesn't:

http://dev.catwalkyourself.com/ready-to-wear/seasons/autumn-winter-2012-2013-en

It throws a 404 error. You can try pasting the links yourself.

Here is my relevant plugin code:

Here is where the custom post type is registered

$post_types = array();

    $post_types['rtw'] =  $args = array(
        'labels' => array(
            'name' => __('RTW Collections'),
            'singular_name' => __('Ready to Wear Collection'),
            'add_new' => __('Add new RTW collection'),
            'add_new_item' => __('Add a new show to the RTW collection'),
            'edit_item' => __('Edit Collection'),
            'view_item' => __('View Collection'),
            'search_items' => __('Search Ready to Wear Collections'),
            'not_found' => __('No RTW Collections found'),
            'not_found_in_trash' => __('No RTW Collections found in trash')
        ),
        'query_var' => 'rtw_collections',
        'supports' => array('title', 'editor', 'thumbnail', 'author', 'comments'),
        'has_archive' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'taxonomies' => array('seasons','city'),
        'rewrite' => array(
            'slug' => 'ready-to-wear',
            'with_front' => false
        ),
        'public' => true,
        'menu_position' => 6
    );

Here is where the taxonomy is configured:

$taxonomies = array();

    $taxonomies['seasons'] = array(
        'query_var' => 'seasons',
        'rewrite' => array(
            'slug' => 'seasons',
            'with_front' => false
        ),
        'single_value' => true,
        'required' => true,
        'labels' => array(
            'name' => __('Seasons'),
            'singular_name' => __('Season'),
            'edit_item' => __('Edit Season'),
            'update_item' => __('Update Season'),
            'add_or_remove_items' => __('Add or remove seasons'),
            'new_item_name' => __('Add new Season'),
            'all_items' => __('All Seasons'),
            'search_items' => __('Search Seasons'),
            'popular_items' => __('Popular Seasons'),
            'separate_items_with_commas' => __('Separate Items with commas'),
            'choose_from_most_used' => __('Choose from most used Seasons')
        )
    );

and here is the call to register_taxonomy:

foreach ($taxonomies as $taxonomy => $arr) {
            register_taxonomy($taxonomy, null, $arr);
        }

I have tried:

  • Flushing the permalinks repeatedly
  • Setting 'with_front' true and false repeatedly
  • add flush_rewrite action to my functions.php

Unfortunately, none of these work. Please help me out.

3 Answers 3

3

I solved this issue by making sure that the calls to register my taxonomies were placed before the calls to registering my custom post types. Weird but it works!

2
  • 4
    OMG thank you for this!!! i was tearing my hair out. No idea why that fixed all the mysterious issues I've been having but it did. THANKS!
    – Michelle
    Jan 23, 2014 at 22:57
  • I swear, I have been searching for this answer for two weeks. I will be embedding the link in the comments of my code! F-YEAH!!
    – jeffjenx
    Dec 19, 2015 at 20:06
0

In my case, WP route system understands it should serve the archive, but ends up serving index.php instead. I wrote this filter to serve the correct template file instead:

add_filter('template_include', function ($template) {
    global $wp;

    switch ($wp->request) {
        case 'myCategory':
            return get_stylesheet_directory() . '/archive-my-category.php';
        case 'myOtherCategory':
            return get_stylesheet_directory() . '/archive-my-other-category.php';
        default:
            return $template;
    }
});
-3

Add

flush_rewrite_rules();

After your register_taxonomy() function

2
  • 2
    Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Jul 11, 2014 at 11:23
  • 1
    Flushing rewrite rules on every request comes with a huge performance drawback.
    – kaiser
    Jul 11, 2014 at 11:42

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.