[wp-trac] [WordPress Trac] #38360: WP does not return attached media

WordPress Trac noreply at wordpress.org
Wed Oct 19 07:01:06 UTC 2016


#38360: WP does not return attached media
--------------------------+------------------------------
 Reporter:  blatan        |       Owner:  joemcgill
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  4.6.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by blatan):

 Hi @joemcgill,


 take a look below.

 This is my SQL query
 {{{
 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;
 }}}

 `$r` array in `get_children()` is

 {{{
 Array
 (
     [numberposts] => -1
     [post_type] => any
     [post_status] => any
     [post_parent] => 1510
 )
 }}}

 `$r array in `get_posts()` after `$r = wp_parse_args( $args, $defaults );`
 {{{
 Array
 (
     [numberposts] => -1
     [category] => 0
     [orderby] => date
     [order] => DESC
     [include] => Array
         (
         )

     [exclude] => Array
         (
         )

     [meta_key] =>
     [meta_value] =>
     [post_type] => any
     [suppress_filters] => 1
     [post_status] => any
     [post_parent] => 1510
 )
 }}}



 And this is from the clean version
 {{{
 SELECT wp_posts.*
 FROM wp_posts
 WHERE 1 = 1 AND wp_posts.post_parent = 1 AND wp_posts.post_type IN
 ('post', 'page', 'attachment') AND
       ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
 draft'))
 ORDER BY wp_posts.post_date DESC;
 }}}

 where the same `$r` is
 {{{
 Array
 (
     [numberposts] => -1
     [post_type] => any
     [post_status] => any
     [post_parent] => 1
 )

 }}}


 `$r array in `get_posts()` in clean WP after `$r = wp_parse_args( $args,
 $defaults );`
 {{{

 Array
 (
     [numberposts] => -1
     [category] => 0
     [orderby] => date
     [order] => DESC
     [include] => Array
         (
         )

     [exclude] => Array
         (
         )

     [meta_key] =>
     [meta_value] =>
     [post_type] => any
     [suppress_filters] => 1
     [post_status] => any
     [post_parent] => 1
 )
 }}}




 Both WP are 4.6.1



 The problem is here:
 {{{
       AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status =
 'pending'))
 }}}

 If I replace the above line to:
 {{{
 ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
 draft'))
 }}}

 my query returns attachments as it is expected.


 Hope this helps.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38360#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list