#16233 closed defect (bug) (worksforme)
Custom taxonomy archive returns 404 when it contains only custom post types
Reported by: | sillybean | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Taxonomy | Keywords: | dev-feedback |
Focuses: | Cc: |
Description (last modified by )
I'm working with a few custom taxonomies that are registered only for a custom post type, not posts or pages. The archive pages return 404s unless I add posts or pages to the taxonomy's content object argument.
Here's the post type:
register_post_type( 'course', array( 'labels' => array( 'name' => __( 'Courses' ), 'singular_name' => __( 'Course' ), 'add_new' => __('Add New'), 'add_new_item' => __('Add New Course'), 'edit_item' => __('Edit Course'), 'new_item' => __('New Course'), 'view_item' => __('View Course'), 'search_items' => __('Search Courses'), 'not_found' => __('No courses found'), 'not_found_in_trash' => __('No courses found in Trash'), 'menu_name' => __('Courses'), ), 'capability_type' => 'post', 'map_meta_cap' => true, 'capabilities' => array( 'edit_post' => 'edit_course', 'read_post' => 'read_course', 'delete_post' => 'delete_course', ), 'description' => __('Individual course data'), 'public' => true, 'show_ui' => true, 'hierarchical' => false, 'menu_icon' => get_bloginfo('template_url').'/images/bank.png', 'register_meta_box_cb' => 'course_meta_boxes', 'supports' => array( 'title', 'editor', 'author', 'excerpt', 'custom-fields', 'revisions',) ) );
And one of the taxonomies:
register_taxonomy( 'college', 'course', array( 'labels' => array( 'name' => __( 'Colleges' ), 'singular_name' => __( 'College' ), 'search_items' => __( 'Search Colleges' ), 'popular_items' => __( 'Popular Colleges' ), 'all_items' => __( 'All Colleges' ), 'parent_item' => __( 'Parent College' ), 'parent_item_colon' => __( 'Parent College:' ), 'edit_item' => __( 'Edit College' ), 'update_item' => __( 'Update College' ), 'add_new_item' => __( 'Add New College' ), 'new_item_name' => __( 'New College Name' ), 'separate_items_with_commas' => __( 'Separate colleges with commas' ), 'add_or_remove_items' => __( 'Add or remove colleges' ), 'choose_from_most_used' => __( 'Choose from the most used colleges' ), 'menu_name' => __('Colleges'), ), 'hierarchical' => true, ) );
Create a few courses, assign them to colleges, and the archives (e.g. /college/liberal-arts) don't work.
If I change the taxonomy definition to include posts (or pages), the archive suddenly work.
register_taxonomy( 'college', 'course', array( 'labels' => array(), 'hierarchical' => true, ) );
Change History (14)
#3
@
14 years ago
- Keywords dev-feedback 3.2-early added
- Milestone changed from Awaiting Review to Future Release
This is "by design" for loops, custom post types don't show in the standard loop, or archive loops.
Taxonomies default to listing posts only, If it applies to other post types, then they're skipped unless you add it by hooking and modifying the queryvars on load.
In my opinion, If a custom taxonomy is registered as public, then it should be querying all registered post types to that taxonomy.
Date Timeline archive views are different, and like pages, custom post types should be excluded as currently happens.
#4
@
14 years ago
Thank you for fixing the formatting. :) And yes, I expected that the taxonomy archive would show all the registered post types, even if the date-based archives do not.
#5
@
14 years ago
Ok, It's just been pointed out to me, that i'm wrong.
Taxonomy archives *should* be returning posts in "any" post types, that excludes certain internal post types (is_public = false i think)
Let me try this out..
#7
@
14 years ago
Had a similar issue... If you just need it working, I think the following should work:
add_action( 'pre_get_posts', 'on_pre_get_posts' ); function on_pre_get_posts() { global $wp_query; if ( is_tax( 'college' ) ) $wp_query->set( 'post_type', array( 'any' ) ); }
#8
@
14 years ago
Oddly enough, this also works:
- Create the taxonomy and assign it to both the CPT and a built-in type (posts).
- Activate plugin.
- Without doing anything else, deactivate plugin.
- Remove the built-in type, and reactivate with only the CPT.
Archives work after that.
This has the feel of a caching problem, maybe related to #16182?
#10
@
14 years ago
I think it should be $wp_query->set( 'post_type', 'any' );
- any as an array does not work for me (latest trunk), though (custom-)post-types do.
Can anybody confirm this?
ARGH, sorry about the formatting. I thought I hit Preview. :(