[wp-trac] [WordPress Trac] #38360: WP does not return attached media
WordPress Trac
noreply at wordpress.org
Tue Oct 18 23:23:41 UTC 2016
#38360: WP does not return attached media
--------------------------+-----------------------------
Reporter: blatan | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.6.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi.
I spent few thinking why my function does not work. Then I started
debugging SQL queries.
I've got few pictures attached to my post.
I used `get_children(get_the_ID()` and I got nothing.
Similar effect with get_attached_media and get_posts with arguments (like
post_parent).
What I noticed?
SQL query from get_children looks like the below:
{{{
SELECT wp_posts.* FROM wp_posts
WHERE 1=1
AND wp_posts.post_parent = 1510
AND wp_posts.post_type IN ('post', 'page', 'attachment', 'teams',
'projects', 'technologies-list')
AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status =
'pending'))
ORDER BY wp_posts.post_date DESC
}}}
I started thinking it could be wrong, because post_status of the images is
inherit. I changed the status in DB to publish and it started working.
I thought I figured out where the reason is, but now I'm no longer sure.
I'm sure in the above query `wp_posts.post_status = 'inherit'` is omitted
for post_type=attachment.
In `get_posts()` you set `post_status` to `'inherit'` if it is attachment
but it seems not to work, even if I pass post_status to the function.
Then the query is built and post_status is checked if it is equal to
`'publish'` and it should be checked if it is inherit and if so the status
of its parent should be checked.
If you have any question I'm at your service.
Kind regards,
Bernard
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38360>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list