[wp-trac] [WordPress Trac] #22960: grab the images of a gallery
WordPress Trac
noreply at wordpress.org
Mon Dec 17 15:39:33 UTC 2012
#22960: grab the images of a gallery
--------------------------+----------------------
Reporter: kcssm | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Media | Version: 3.5
Severity: normal | Resolution: invalid
Keywords: needs-codex |
--------------------------+----------------------
Changes (by SergeyBiryukov):
* keywords: => needs-codex
* status: new => closed
* resolution: => invalid
* severity: major => normal
* milestone: Awaiting Review =>
Comment:
> And as of WordPress 3.5, galleries are no more related to particular
post.
Related: #22439
The ability to specify attachment IDs in a gallery shortcode isn't new to
3.5, it just got a handy UI.
You can grab attachment IDs from a gallery with a snippet like this:
{{{
function grab_attachment_ids_from_gallery() {
global $post;
$attachment_ids = array();
$pattern = get_shortcode_regex();
if ( preg_match_all( "/$pattern/s", $post->post_content, $matches
) ) {
if ( $key = array_search( 'gallery', $matches[2] ) )
$atts = shortcode_parse_atts( $matches[3][ $key ]
);
if ( isset( $atts['ids'] ) )
$attachment_ids = explode( ',', $atts['ids'] );
}
echo '<pre>'; print_r( $attachment_ids ); echo '</pre>';
}
add_action( 'wp', 'grab_attachment_ids_from_gallery' );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22960#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list