Support

Account

Home Forums Gutenberg GutenBerg block to get first gallery image from custom post type

Unread

GutenBerg block to get first gallery image from custom post type

  • I have a custom post type named “models” and created a GutenBerg block to display all models.

    Each single model has a gallery field.

    I am trying to show the first image from the “model_gallery” field kind of like a featured image for each model that is displayed in the loop.

    I have tried using the code below in my “/template-parts/blocks/models/display-models.php” file where the loop is:

    <?php 
            $images = get_field('model_gallery'); 
            $image_1 = $images[0]; 
            ?>    
    
    <img src="<?php echo $image_1[url]; ?>" /> 

    I currently have the gallery Return Format set as “image url” and I have tried using array, and ID as well.

    I can only assume since this has always worked when working with non GutenBerg blocks that this must have something to do with the templating structure of GutenBerg.

    Does anyone know how to get this to work?

Viewing 1 post (of 1 total)

The topic ‘GutenBerg block to get first gallery image from custom post type’ is closed to new replies.