Skip Navigation

[Resolved] Creating a random order of gallery images from different cpts

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#695915

I am trying to create a gallery using a cpt. the gallery cpt has repeating fields for the images. i have created a gallery with a random order for the images. at the moment the images are not randomly order instead the cpts are the ones being randomly ordered.

Link to a page where the issue can be seen:
hidden link

I wanted to have images to ordered randomly not just the cpts.

#696237

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

How have you made your gallery?

A View can query posts and return them in a random order, but if you are using wpv-for-each to iterate over repeating fields there is no way to do that any way other than sequentially.

So what you are asking may not be possible, but if you can tell me more about how you have set up your gallery I may be able to help.

#696331
screenshot.PNG

sorry about that. I have created the gallery using this code:

	[wpv-for-each field="wpcf-gallery-images"] 
		
			<div class="col-sm-4"><a href="[types field='gallery-images' size='full' url='true' separator=','][/types]" target="_self" itemprop="url" class="lightbox-image" data-target="[types field='gallery-images' size='full' url='true' separator=','][/types]" target="_self">
        [types field='gallery-images' width='296' height='197' align='center' resize='crop' separator=', '][/types]<br />
    </a>
		</div>
		
	
		[/wpv-for-each]

here is also the screenshot of the code.

if using wpv-for-each to iterate the repeating fields is not yet possible. Iis there another way we can iterate the repeating fields without using wpv-for-each?

#697895

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, I see.

Yes, well, it is as I stated above, that the queries for the posts can return results in random order, but not iterating over the custom fields with wpv-for-each.

The are two possible solutions.

One would be to write a custom shortcode that you use in place of wpv-for-each that effectively does the same thing—outputs each instance of the custom field for the current post—but in random order.

The alternative that wouldn't require any custom coding would be to add the images individually to a new post type which is a child post of the post types included in your current View.

Then, in place of having a wpv-for-each loop to iterate over the custom fields of the current post, you would insert a nested View which returned the child posts in random order (in the required format).