0

I have a custom post type that looks like:

register_post_type( 'letters', array(
    'labels' => array(
        'all_items' => __( 'All Letters', 'text_domain' ),
        'name' => __( 'Letters' ),
        'search_items' => __('Search Letters'),
        'singular_name' => __( 'Letter' ),
        ),
        'has_archive' => true,
        'menu_icon' => 'dashicons-media-document',
        'menu_position'=> 5,
        'public' => true,
        'rewrite' => array('slug' => 'letters'),
        'supports' => array( 'title', 'editor', 'author' ),
    )
);

Then, I have a custom taxonomy that looks like:

function create_letter_taxonomies() {
    $labels = array(
        'add_new_item' => __( 'Add New Tag' ),
        'add_or_remove_items' => __( 'Add or remove tags' ),
        'all_items' => __( 'All Tags' ),
        'choose_from_most_used' => __( 'Choose from the most used tags' ),
        'edit_item' => __( 'Edit Tag' ), 
        'menu_name' => __( 'Tags' ),
        'name' => _x( 'Tags', 'tag' ),
        'new_item_name' => __( 'New Tag Name' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'popular_items' => __( 'Popular Tags' ),
        'search_items' =>  __( 'Search Tags' ),
        'separate_items_with_commas' => __( 'Separate tags with commas' ),
        'singular_name' => _x( 'Tag', 'tag' ),
        'update_item' => __( 'Update Tag' ),
    );

    register_taxonomy('letter_tags','letters', array(
            'hierarchical' => false,
            'labels' => $labels,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'tags' ),
            'show_admin_column' => true,
            'show_ui' => true,
            'update_count_callback' => '_update_post_term_count',
        )
    );
}

What I am struggling with is how the taxonomy is working with my template. Through the admin panel I can add tags for my custom post type. http://joshrodg.com/hallmark/letters/ works but http://joshrodg.com/hallmark/letters/tags/moore/ doesn't work and http://joshrodg.com/hallmark/letters/tags/kenya/ doesn't work.

The archive page I have is: taxonomy-letter_tags.php...am I missing something? I am trying to understand why I'm getting a 404 instead of seeing the taxonomy-letter_tags.php template?

Thanks,
Josh

0

So, it looks like I didn't understand how a custom taxonomy works.

http://joshrodg.com/hallmark/letters/tags/moore/ should be http://joshrodg.com/hallmark/tags/moore/ and http://joshrodg.com/hallmark/letters/tags/kenya/ should be http://joshrodg.com/hallmark/tags/kenya/.

My mistake was that I expected the tags to be linked off my custom post type url, and not my main domain. I found the answer here: Archive template for taxonomy terms

Thanks,
Josh

0

Often there is a small bug that appears intermittently where correct post permalinks redirect to 404 pages, when this happens:

Go to your back office > Settings > permalinks, change values randomly then save and then edit them again back as you want them to be and save. This forces new permalinks structures to update properly. I found that wordpress has bugs with this and found this little trick quite handy and stable. Be careful when doing this, deactivate any XML sitemap plugins you may have in place.

But I think you should have a look at your rewrite option.

'rewrite' => array( 'slug' => 'tags' ),

'rewrite' => array( 'slug' => '%show_category%/%postname%', 'with_front' => false )
4
  • actually just loading the permalinks settings page flushes and rebuilds rewrite rules, you don't have to edit or save anything.
    – Milo
    Mar 24 '16 at 18:29
  • from the codex: "You can do it manually by going to the Permalink Settings page and re-saving the rules -- you don't need to change them -- or by calling $wp_rewrite->flush_rules()." So actually you need to press save, otherwise, it shouldn't work. Unless they flush_rules() when opening the page. I was doing an unnecessary change.
    – db306
    Mar 25 '16 at 13:46
  • The Codex can be edited by anyone and is often wrong. If you look at the source of options-permalinks.php you can see where it flushes rules on every load of options-permalink.php, no save is necessary.
    – Milo
    Mar 25 '16 at 16:12
  • 1
    Good to know. As anyone can edit the codex you could correct that mistake and have a valuable input for the community.
    – db306
    Mar 27 '16 at 16:40

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.