Home Forums Add-ons Gallery Field Accessing images in a gallery on user profile from PHP


Accessing images in a gallery on user profile from PHP

  • I’m working on a site for an arts organisation where we need list profiles, each including a main image and gallery of images.

    Using ACF (and ACF Pro), I’ve added additional fields to user’s profiles, and want to be able to show all profiles matching particular criteria. The main image is added as an ACF image and the gallery is an ACF gallery.

    There are lots of fields to show, but in essence I am showing them by going:

    $allusers = get_users(array(
    ‘orderby’ => ‘last_name’,
    ‘order’ => ‘ASC’

    <?php foreach ( $allusers as $user ) {
    $usermeta = get_user_meta ($user->ID);

    <div class=FirstName>First name: <?php echo $usermeta[‘first_name’][0]; ?></div>
    <div class=LastName>Last name: <?php echo $usermeta[‘last_name’][0]; ?></div>

    <?php if (isset($usermeta[‘main_image’])){
    $image_url = wp_get_attachment_image_src( $usermeta[‘main_image’][0] , ‘thumbnail’ )[0];
    <div class=MainImage><img src=”<?php echo $image_url ?>” /></div>
    galler<?php } ?>
    <?php } ?>`

    But I can’t see a way to get the individual images in the gallery. When I try to go print_r($usermeta) it includes the following (for a gallery with four images):

    [gallery] => Array ( [0] => a:4:{i:0;s:3:”540″;i:1;s:3:”264″;i:2;s:3:”266″;i:3;s:3:”543″;} )

    What I am hoping is that it will be possible to get an array of URLs for the images in the gallery. This would be my ideal, but is there any way to access these images from PHP (so I can insert them in a web page)

  • @markargent could this help, How to get value from a user, ACF docs

     * get current author, use this on single page
    $author_id = get_the_author_meta('ID');
    $author_image = get_field( 'author_image', 'user_'.$author_id );
    $author_image_size = 'medium';
    <?php if( get_field( 'your_field_image', 'user_'.$author_id ) ) : ?>
    	<?php the_field( 'your_field_image', 'user_'.$author_id ); ?>;"
    <?php endif; ?>>
    <!-- get just img with wp_get_attachment  -->
    <?php echo wp_get_attachment_image( $author_image['ID'], $author_image_size,"", array( "class" => "custom-class-name" ) ); ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.