edit.php only queries for 'blog' posts
-
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.”
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.
What would be the best way to fix/hack this?
- The topic ‘edit.php only queries for 'blog' posts’ is closed to new replies.