Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#34702 closed defect (bug) (duplicate)

get_post_galleries( $post->post_parent ) not working in the loop of attachment.php

Reported by: drlightman's profile DrLightman Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Gallery Keywords:
Focuses: Cc:

Description

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
// 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( );

Change History (1)

#1 @pento
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version 4.3.1 deleted

Thank you for the bug report, @DrLightman! There's some progress on this bug on #39304, so let's continue the discussion there.

Note: See TracTickets for help on using tickets.