0

I dont understand why this returns nothing but a blank screen.

But if you echo the $attachment->ID you get a string of ID numbers.

The goal is to produce a gallery with the wordpress [gallery] shortcode that includes all the featured images in all post.

$args = array( 'posts_per_page' => -1, 'offset'=> 1, 'post_type' => 'attachment' );

$posts = get_posts( $args );

foreach ( $posts as $attachment ) {
              do_shortcode('[gallery type="square" id="'.$attachment->ID.' ,"]');
    }

Also, which is it: ID or IDS (the codex shows both?!) and which is better to use ID or INCLUDE to pick which images to use?

NOTE: Tried this in default 20-13 and 20-14 themes, got the same blank results.

2

First get all of the feature thumbnail ids, and then populate the gallery. Code -

<?php
global $wpdb;
$featured_ids = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_thumbnail_id'");
$featured_ids = array_map('intval', $featured_ids);
$featured_ids = array_unique($featured_ids);

echo do_shortcode('[gallery type="square" ids="'. implode(',', $featured_ids ).' ,"]');
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.