Skip Navigation

[Resolved] Creating Pagination for a Multi-instance Custom Field

This support ticket is created 5 years 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by andrei-laurentiuP 5 years ago.

Assisted by: Shane.

Author
Posts
#1402609

I have a multiple-instances image custom field where users can add images for a gallery. Is there any way to create a view/content template with pagination for the custom field values so they would not load all at once?

#1403071

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andrei,

Thank you for getting in touch.

Is this a repeatable image field or is it a repeatable field group with the image field?

Please let me know.

Thanks,
Shane

#1403153

Hi, Shane. It is a repeatable image field.. not a repeatable group.

#1403317

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andrei,

The easiest way to do this is by using repeatable field groups, however we can still do it with the repeatable fields with some 3 party code.

Take a look at the link below.
https://toolset.com/forums/topic/generate-slide-on-my-slider/

You should see in my custom solution how to use flexslider to create a slider with your repeatable images.

To customize the flexslider you can take a look at the flexslider documentation below.
hidden link

Please let me know if this helps.
Thanks,
Shane

#1403605

Hi Shane,

Thank you, I have tested the plugin and it works. The trouble is that the issue that I have is still there since if you have a relatively large number of images in the gallery, then the page would load slowly. I was thinking to limit the images size and number, but the issue somehow would still be there as I wouldn't limit it too much. So, what I was thinking was to split the custom field array and to display it using some pagination...

#1404345

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andrei,

Given that you are using a repeatable field then it wouldn't be possible to paginate through them. What would happen is that you will need to load them all at once and use the setup that I sent previously to paginate through them as a gallery.

With Repeatable field groups your are able to paginate through a set of them at a time, but you will need to be uploading the images one at a time, which i suspect would be an undesirable result for you.

What you can do is to leverage the load time with the use of caching so views won't need to hit the database each time this page is loaded.

One caching plugin you can use is the WP Super cache
https://wordpress.org/plugins/wp-super-cache/

Please let me know if this helps.
Thanks,
Shane

#1406127

Hey Shane,

Just now I thought that since I have only one custom field where I intend to store images/attachments for the gallery post, maybe I could create a view to display the Media attached to the post itself. However, I don't see how to create a proper query for that... Maybe I could use this: https://developer.wordpress.org/reference/functions/wp_get_attachment_url/ ?

function wp_get_attachment_url( $attachment_id = 0 ) {
$attachment_id = (int) $attachment_id;
$post = get_post( $attachment_id );
if ( ! $post ) {
return false;
}

if ( 'attachment' != $post->post_type ) {
return false;
}

Maybe adding a shortcode for filtering.. :-?? I will have a look into it tomorrow (it's late here)... until then, maybe you could give me any hint if this should be the way or if I should try something else?

#1407133

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andrei,

Unfortunately I dont think wordpress has a way of handling this particular issue because you still wouldn't be able to dynamically load your images on request.

There is a pagination setting for wordpress but this only applies to posts and not post meta. Essentially you're not able to pagination through the different items in a custom field.

You will need to load it in its entirety and then paginate through it dynamically on the frontend using the solution that i've previously advised.

Anything outside of this would require some advanced coding and use of SQL queries to get the values from the array of images.

Thanks,
Shane

#1407215

Thank you, Shane.. I spent some time today thinking on this matter. You are right, it can be done only with advanced coding which is out of the scope and beyond my capabilities at the moment. I will look into it some other time. My issue is resolved for now. Thank you!