[wp-trac] [WordPress Trac] #28628: Query for "Mine" link in edit.php is not aware of custom post types
WordPress Trac
noreply at wordpress.org
Wed Jun 25 13:25:33 UTC 2014
#28628: Query for "Mine" link in edit.php is not aware of custom post types
--------------------------+-----------------------------
Reporter: webmaster808 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.9.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28628>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list