Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#13755 closed defect (bug) (fixed)

Custom Post Type/Taxonomy in non-published status

Reported by: ajferg Owned by:
Milestone: 3.0 Priority: high
Severity: major Version: 3.0
Component: Administration Keywords:
Focuses: Cc:


I'm using a custom post type (product) and taxonomy (brand), and have discovered a problem in the admin area with WP3.0 RC2

I have some 'products' as Private, and some Published. Visiting:
only shows the Published ones. I haven't been able to find any way to display posts of Product type, in a particular brand, with a non-published status.

This is how I'm declaring my custom type/tax. I've tried plenty of variations with the args.

// Set up custom Post Types & Taxonomies
add_action('init', 'register_custom_post_types', 7);	
function register_custom_post_types() {
	register_post_type('product', array(
		'labels' => array(
			'name' => 'Products',
			'singular_name' => 'Product',
			'edit' => 'Products',
			'add_new' => 'Add Product',
		'public' => true,
		'capability_type' => 'post',
		'publicly_queryable' => true,
		'exclude_from_search' => false,
		'show_ui' => true,
		'query_var' => true,
		'_edit_link' => 'post.php?post=%d',
		'capability_type' => 'post',
		'hierarchical' => false,
		'menu_position' => null,
		'rewrite' => array('slug' => 'products'),
		'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail' )
	register_taxonomy( 'brand', array('product'), array(
		'labels' => array(
			'name' => 'Brands',
			'singular_name' => 'Brand',
			'search_items' => 'Search Brands',
			'popular_items' => 'Popular Brands',
			'all_items' => 'All Brands',
		'public' => true,
		'show_ui' => true,
		'show_tagcloud' => false,
		'hierarchical' => true,
	// Unnecessary?
	register_taxonomy_for_object_type('brand', 'product');
	// This might save some 404 problems?
	global $wp_rewrite;

Attachments (2)

13755.diff (547 bytes) - added by ryan 10 years ago.
13755.2.diff (433 bytes) - added by ryan 10 years ago.
Don't force post_status for tax queries.

Download all attachments as: .zip

Change History (7)

#1 @ryan
10 years ago

wp_edit_post_query() isn't allowing a post_status of any through. This causes get_posts() to be run without a post_status being set. We fall into the is_tax case and the set post_status to publish since it is not set. I think we can allow 'any' in wp_edit_post_query(). Ideally we wouldn't have to pass 'any' for custom taxonomies since it is not required for the builtin taxonomies. This would require getting rid of the line in the is_tax case that set post_status to publish, which has been debated before.

10 years ago

#2 @ryan
10 years ago

Actually, allowing 'any' is too aggressive since it causes some cap checks to be skipped.

10 years ago

Don't force post_status for tax queries.

#3 follow-up: @ryan
10 years ago

I don't see why we're forcing the post status for tax queries. Remove those two lines and tested frontend and backend queries while logged out and while logged in with a user with read private posts capability and a user without read private cap.

#4 in reply to: ↑ 3 @ajferg
10 years ago

  • Cc ajferg added

Thanks Ryan - I've tested 13755.2.diff, and that solves my problem.

#5 @ryan
10 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [15173]) Don't force post_status to publish for custom taxonomy queries. fixes #13755

Note: See TracTickets for help on using tickets.