Frage

How to get images from a gallery in a post in WordPress 3.5 as gallery is no longer related to posts in 3.5. get_children() doesnot work as gallery is not attachment. Any help is appreciated.

War es hilfreich?

Lösung 2

`global $post;
    $post_subtitrare = get_post( $post->ID );
    $content = $post_subtitrare->post_content;
    $pattern = get_shortcode_regex();
    preg_match( "/$pattern/s", $content, $match );
    if( isset( $match[2] ) && ( "gallery" == $match[2] ) ) {
        $atts = shortcode_parse_atts( $match[3] );
        $attachments = isset( $atts['ids'] ) ? explode( ',', $atts['ids'] ) : get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID .'&order=ASC&orderby=menu_order ID' );
    }`

The $attachments will get you what you are used to getting prior to WordPress 3.5.

Andere Tipps

You must probably parse shortcode:

http://codex.wordpress.org/Gallery_Shortcode

Use regular expression:

$post_content = get_the_content();
preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
$array_id = explode(",", $ids[1]);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top