Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:22:25+00:00 2026-06-15T05:22:25+00:00

I am using the Advanced Custom Fields plugin in WordPress to implement a gallery

  • 0

I am using the Advanced Custom Fields plugin in WordPress to implement a gallery into my site. I would like to display 5 random images from the gallery field.

I have the following code which displays all images from the gallery field:

    <?php $images = get_field('gallery');
      if( $images ): ?>
        <?php foreach( $images as $image ): ?>
          <img scr="<?php echo $image['url']; ?>">
        <?php endforeach; ?> 
    <?php endif;  ?>

Print_r of $images results in the following output:

Array ( [0] => Array ( [id] => 46 [alt] => [title] => 500x10002  =>  [description] =>   [url] => 500x1000.jpg [sizes] => Array ( [thumbnail] => 500x1000-100x100.jpg [medium] => 500x1000-150x300.jpg [large] => 500x1000.jpg [post-feature-image] => 500x1000.jpg ) ) [1] => Array ( [id] => 45 [alt] => [title] => 500x500  => [description] =>   [url] => 500x500.jpg [sizes] => Array ( [thumbnail] => 500x500-100x100.jpg [medium] => 500x500-300x300.jpg [large] => 500x500.jpg [post-feature-image] => 500x500.jpg ) ) [2] => Array ( [id] => 44 [alt] => [title] => 2000x500  => [description] =>   [url] => 2000x500.jpg [sizes] => Array ( [thumbnail] => 2000x500-100x100.jpg [medium] => 2000x500-300x75.jpg [large] => 2000x500-1024x256.jpg [post-feature-image] => 2000x500-610x152.jpg ) ) [3] => Array ( [id] => 43 [alt] => [title] => 1000x500  => [description] =>   [url] => 1000x500.jpg [sizes] => Array ( [thumbnail] => 1000x500-100x100.jpg [medium] => 1000x500-300x150.jpg [large] => 1000x500.jpg [post-feature-image] => 1000x500-610x305.jpg ) ) [4] => Array ( [id] => 42 [alt] => [title] => 500x2000  => onderschifttttt [description] =>   [url] => 500x2000.jpg [sizes] => Array ( [thumbnail] => 500x2000-100x100.jpg [medium] => 500x2000-75x300.jpg [large] => 500x2000-256x1024.jpg [post-feature-image] => 500x2000.jpg ) ) ) 

Any help greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:22:26+00:00Added an answer on June 15, 2026 at 5:22 am

    Your logic might look like this:

    $max_images_to_show = 5;
    $images_available = count($images);
    $images_to_show = array();
    
    if ($images_available <= $max_images_to_show) {
        $images_to_show = $images;
    } else {
        while(count($images_to_show) < $max_images_to_show) {
            $random_index = rand(0, count($images) - 1);
            $images_to_show[] = array_slice($images, $random_index, 1);
        }
    }
    
    // show images from $images_to_show
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Advanced Custom Fields wordpress plugin and I am outputting the
I am using advanced custom fields in Wordpress. Without going into the details of
I am using wordpress's advanced custom fields, which uses the syntax get_field('custom_field_name'); to pull
I'm using the http://www.advancedcustomfields.com plugin to create custom fields in Wordpress. I'm specifically using
I'm using custom plugin for jQuery UI datepicker - Timepicker I have two fields,
I am using the Wordpress plugin Woocommerce. The system uses attributes to display product
I want to add some custom fields to add new user in Wordpress .
I would like to know how to use the custom SPFieldType (Existing on the
I am currently using the Html.EditorFor<> method for generating editor fields, however I would
I am using Advanced DataGrid of Flex 3 with hierarchical data. The itemRenderer is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.