Skip Navigation

[Resolved] How to output repeatable field groups on the front-end in the same order as the backend?

This thread is resolved. Here is a description of the problem and solution.

Problem:
In the backend post edit screens repeatable field groups can be re-ordered with drag and drop. How can they be output on the front-end in the same order?

Solution:
The order is stored as a custom field "toolset-post-sortorder", and so the View settings for ordering need to order by that custom field.

This support ticket is created 4 years, 11 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+01:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by CraigS3893 4 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1239099
Screen Shot 2019-05-03 at 14.50.17.png
Screen Shot 2019-05-03 at 14.50.06.png

Hi
Think there's a bug with repeating field blocks. I've created a simple 'page builder' for a client with various content block types, as repeatable field groups. However, when these are re-ordered in the back-end, the changes aren't reflected on the front-end. The site is still in development so can't share a link but screengrabs are attached. The "Quality" panel should be appearing above the "Download" one. I've updated to 3.2.7 and the issue is still there.

#1239109

Nigel
Supporter

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

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

Screenshot 2019-05-03 at 15.04.28.png

Hi Craig

The sort order is stored as post meta with a key of toolset-post-sortorder, so that's what you need to set in your View that outputs the fields on the front end.

See my screenshot, hopefully that is clear.

#1239115

Hi Nigel, thanks for the quick response. I haven't started using Views yet - I'm still doing it all programatically in the template files.

Can I do this within the toolset_get_related_posts function?

<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'page-content', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>

#1239128

Nigel
Supporter

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

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

According to the documentation for toolset_get_related_posts you can include 'meta_value' or 'meta_value_num' as an orderby option, which looks promising, but only if you include a meta_key argument for meta_query filter, which is only partially implemented and supports only '=' or 'LIKE', but you don't want to specify what that custom field value is.

So it sounds like you cannot.

Which means a slightly tedious loop over the child posts to get the toolset-post-sortorder custom field value for each post and then sorting them into the required order, before you then loop over that sorted array to output you content as required.

It might be easier if you create a View with the relevant settings and in your PHP template where you want the View results to appear use the render_view function: https://toolset.com/documentation/programmer-reference/views-api/#render_view

Would that work?

#1239135

Thanks. I really need to get started using Views but I'm stuck using the methods I'm comfortable with at the moment. The loop is already quite big, with conditional options for various layout types, so wrapping it in another one would be too much I think. I'll just make sure the content is added in the correct order and ignore the re-ordering function for now.

Thanks for the advice!

#1239136

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.