Support

Account

Home Forums Add-ons Gallery Field Display Gallery of specify post

Solved

Display Gallery of specify post

  • Hello!

    I ask for help with the code. Now I use this code to display a gallery of the current post:

    <?php 
    $image_ids = get_field('photo', false, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    echo do_shortcode( $shortcode );
    ?>

    I want to change it. I need to display a gallery of the specify post, I want to select the Post Object field, for example, “post-gallery”.

  • Hi @buylov

    You can create a post object field and then call it like this:

    <?php 
    $galleyPost = get_field('photo', 'post_gallery_field_name', false);
    $image_ids = get_field('photo', $galleyPost, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    echo do_shortcode( $shortcode );
    ?>

    Keep in mind that I haven’t tested it yet.

    I hope this helps.

  • Thank you!
    It only works with the following modification:

    <?php 
    $galleyPost = get_field('post_gallery_field_name', false, false);
    $image_ids = get_field('photo', $galleyPost, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    echo do_shortcode( $shortcode );
    ?>
  • Hi @buylov

    Ah yeah, I’m sorry about that. Something distracted me I guess. Glad that you can fix it for me 🙂

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Display Gallery of specify post’ is closed to new replies.