Skip Navigation

[Resolved] changing order of repeatable field groups

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 5 years, 12 months ago.

Assisted by: Christian Cox.

Author
Posts
#1193894
field-group-order.JPG

I am trying to:

Reorder entries in a repeatable field group.

I have a repeatable field group on a post. I just added two new entries, and want them to appear on top. I changed the order in the admin area, but they appear below the new entries on the front end.

I've uploaded to images, but they are not uploading properly. I'll try again to make it clear.

This is my code in my template:

<?php 
	$child_posts = toolset_get_related_posts( get_the_ID(), 'community-programs', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
	foreach ($child_posts as $child_post) { ?>
	<li>
	<a target="blank" rel="noopener" href="<?php echo (types_render_field( 'program-news-url', array( "id"=> "$child_post->ID" ) ) );?>">
	<?php echo (types_render_field('program-or-news' , array( "id"=> "$child_post->ID" ) ) ); ?></a>
	</li>
<?php } ?>
#1193927

Hi, RFG have a meta value "toolset-post-sortorder" that is used to determine sorting. You could add that meta_key to your toolset_get_related_posts query along with meta_compare, and use meta_value_num in the order argument:

 $child_posts = toolset_get_related_posts( 
  get_the_ID(), 
  'community-programs', 
  array( 
    'query_by_role' => 'parent', 
      'args' => array(
        'meta_key' => 'toolset-post-sortorder',
        'meta_compare' => 'EXISTS'
      ),
      'orderby' => 'meta_value_num',
      'order' => 'ASC',
    'return' => 'post_object' 
  ) 
);

#1196263

Thank you for that code it did work. But it doesn't change the order on a page translated by WPML. Is there anything I have to do? I'm translating manually, not with the translate tool because of conflicts elsewhere on my site.

#1196358

Thank you for that code it did work. But it doesn't change the order on a page translated by WPML.

Which page are you referring to, the translated Community post, or some other post?

Please go to WPML > Settings > Multilingual Content Setup.

Scroll down to Custom field settings. What is the translation setting for toolset-post-sortorder?

Scroll down to the Post Types Translation section. What are the translation settings for the Community post type?