[wp-trac] [WordPress Trac] #34702: get_post_galleries( $post->post_parent ) not working in the loop of attachment.php

WordPress Trac noreply at wordpress.org
Mon Nov 16 17:29:56 UTC 2015


#34702: get_post_galleries( $post->post_parent ) not working in the loop of
attachment.php
--------------------------+-----------------------------
 Reporter:  DrLightman    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Gallery       |    Version:  4.3.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 It returns an empty array.

 I think the bug resides in the chain of calls:

 get_post_galleries >>> do_shortcode_tag >>> gallery_shortcode

 not transmitting the user supplied post ID ($post->post_parent in this
 example) correctly.

 I suppose that '''gallery_shotcode''' in this case erroneously defaults to
 the global loop post ID.

 Infact, I would solve the problem in this way (code to be placed inside
 the loop, in attachment.php, for testing on an attachment (image) page of
 a post with a gallery shortcode):

 {{{#!php
 <?php
 // switch to the parent post, the one holding the [gallery] shortcode(s)
 $post = get_post( wp_get_post_parent_id( get_the_ID( ) ), OBJECT );
 setup_postdata( $post );
 // get the galleries
 $galleries = get_post_galleries( $post, false );
 // VERY IMPORTANT: restore the original post (the attachment)
 wp_reset_postdata( );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34702>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list