Skip Navigation

[Resolved] Order of repeating field group is not reflected on the front of the website

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

Problem:

Sort the repeatable field group items by settings manually by the user in custom codes.

Solution:

Toolset repeatable field group is using a custom field to store the sortby value, you can follow our document to setup the "orderby" parameter

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by julesW 3 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2214815
toolset_order-f-repeating-field-group.png

Hello

I've written some custom code to bring in a repeatable field group. The code works, but it does not respect the order of the puppies added to this repeatable field group (set in the edit post view).

Example link: hidden link (scroll down to "And Their Puppies!")

I've included a screenshot from the "edit post" view and below is the code I'm using.

if(is_singular('litters')){
	$litter_id = get_the_ID();
	$puppies_in_litter_output = '';
	$puppies_in_litter = toolset_get_related_posts( $litter_id, 'litter-puppies', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );		
	foreach ($puppies_in_litter as $puppy){	
		$show_hide_puppy = get_post_meta($puppy->ID, 'wpcf-litter-puppy-show-hide', true);
		if($show_hide_puppy =='show'){ 
			$puppy_full_name = get_post_meta($puppy->ID, 'wpcf-litter-puppy-name', true);
			$puppy_nick_name = get_post_meta($puppy->ID, 'wpcf-litter-puppy-nickname', true);
			$puppy_description = get_post_meta($puppy->ID, 'wpcf-litter-puppy-description', true);
			$puppy_image_slug = get_post_meta($puppy->ID, 'wpcf-litter-puppy-image', true); 			
			$puppy_status = get_post_meta($puppy->ID, 'wpcf-litter-puppy-status', true);
			$shortcode = str_replace('%1$s', $puppy->ID, '[types field="litter-puppy-image" item="%1$s" size="medium" alt="%%ALT%%" output="html"]');
			$thumbnail = do_shortcode($shortcode);
			$puppies_in_litter_output .= sprintf('<div class="et_pb_module et_pb_blurb puppy-item %5$s"><div class="et_pb_blurb_content"><div class="ribbon ribbon-top-left"><span>ribbon</span></div><h3 class="et_pb_module_header nickname">%2$s</h3><div class="et_pb_main_blurb_image"><span class="et_pb_image_wrap">%4$s</span></div><div class="et_pb_blurb_container"><div class="et_pb_blurb_description"><div class="full-name">%1$s</div><div class="description">%3$s</div></div></div></div></div>', $puppy_full_name, $puppy_nick_name, $puppy_description, $thumbnail, $puppy_status);	
		}	
	}	
	if($puppies_in_litter_output!==''){
		echo sprintf('<div class="puppy-container" data-lazy="false">%1$s</div>', $puppies_in_litter_output);
	}
	if($puppies_in_litter_output ==''){
		echo sprintf('<div class="et_pb_module et_pb_text et_pb_text_align_left et_pb_bg_layout_light"><div class="et_pb_text_inner"><p class="text-center">Photos and Profiles Coming Soon!</p></div></div>');
	}	
}

Is this something you can help me with?

Thank you
Jules

#2215533

Hello,

Toolset repeatable field group is using a custom field to store the sortby value, you can follow our document to setup the "orderby" parameter
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
'rfg_order' is applicable only for repeatable field groups and it means the order which has been set manually by the user

#2216061

Thank you, Luo. That was exactly what I needed.

For those interested in the answer, all I did was update line 4 to:
$litter_updates = toolset_get_related_posts( $litter_id, 'litter-update', array( 'query_by_role' => 'parent', 'return' => 'post_object', 'orderby' => 'rfg_order' ) );

Cheers!
Jules