Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#28628 closed defect (bug) (invalid)

Query for "Mine" link in edit.php is not aware of custom post types

Reported by: webmaster808's profile webmaster808 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Query Keywords:
Focuses: Cc:

Description

I have been troubleshooting why the "Mine" list of posts is empty for custom post types in edit.php.

At first it appeared that it could be related to capabilities, but on further inspection it looks like the query that is being run has been coded to only search for a selected author's 'blog' posts and not the author's 'post_type' posts.

For instance, I have a CPT named 'testimonial.' I also have a custom user role of 'agent' that has been given all capabilities for this CPT.

In edit.php, when the agent with user ID 25(for example) hits the page, the line above the posts table reads: "Mine (140) | All (695) | Published (695)." However, the table where the 140 "Mine" posts are supposed to be listed, it says "No Testimonials Found." The expected output would be for the "Mine" list to be populated with the user's Testimonial custom posts and not be empty.

When I click on the "All" link, all 695 testimonials show up in the list and the ones that the agent user can edit have checkboxes/links to edit and the ones from other agents are there but can only be read. This is exactly like it is supposed to be and tells me that the permissions/capabilites for this CPT are correct.

The problem is in the query that edit.php uses to build the list of "Mine" posts. I am using the Query Monitor plugin to troubleshoot this and here is what I found.

When the user clicks "All" testimonials, this is the Query that is run:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'testimonial'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'future'
OR wp_posts.post_status = 'draft'
OR wp_posts.post_status = 'pending'
OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
LIMIT 0, 20

When the user selects "Mine," this is the Query that is run:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_author IN (25)
AND wp_posts.post_type = 'blog'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'future'
OR wp_posts.post_status = 'draft'
OR wp_posts.post_status = 'pending'
OR wp_posts.post_author = 25
AND wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
LIMIT 0, 20

The problem is in line 5 where 'blog' should be 'testimonial' or other CPT slug.

I have not tested this with plugins off, because the post type won't exist without plugins.

Change History (1)

#1 @boonebgorges
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

webmaster808 - Thanks for the report.

I'm guessing this is a bug with one or more of your plugins. You've already mentioned your CPT 'testimonial'. But the second query contains wp_posts.post_type = 'blog'. 'blog' is not a WP core post type either. My guess is that whatever plugin creates the 'blog' post type is also doing some sort of filter on post queries - hooking to 'pre_get_posts' or something like that - but is doing it too promiscuously and wrecking the query on the Mine tab.

I created a couple custom post types locally to test, and verified that the counts and posts displayed under Mine matched in all cases.

I suggest finding the plugin that creates the 'blog' post type and disabling it for testing. If you track this down and discover that this is indeed a core bug, please feel free to reopen this ticket with further details.

Note: See TracTickets for help on using tickets.