Skip Navigation

[Resolved] Cannot change order of repeating image field with cred form

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 1 year, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2625549
Screenshot 2023-07-20 at 08.33.08.png

Hi there

Funny thing... I have a repeating image field in a cred form.

If I change the order of the repeating images via the cred form the sorting order is NOT saved.

If I change the order via admin dashboard it works fine.

The wordpress, theme and all the plugins are up to date and there are no error messages that I can see...

I can't see any reason why the form is not saving the change of sorting order anymore...

Hoping you can help!

Rita

#2625621

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL of your form where I can see the issue as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2625757

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There was indeed issue with saving the correct sort order for repeating field with add/edit post form.

I've reported that issue to our next level support but fortunately I've added workaround that will help you to resolve this issue as there is no ETA on when the official fix will be made available.

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_action('cred_save_data', 'ts_save_the_rf_sort_order_manually',10,2);
function ts_save_the_rf_sort_order_manually($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==32) {
    		
      	$field_slug = 'media-gallery';

    	$field_content = $_POST['wpcf-'.$field_slug];
      		
      		$sort_order = array();
      	    
      		delete_post_meta($post_id,'wpcf-'.$field_slug);
      
      		foreach($field_content as $k=>$v):
      			$sort_order[] = add_post_meta($post_id,'wpcf-'.$field_slug,$v);
    		endforeach;
   
      		update_post_meta($post_id,'_wpcf-'.$field_slug.'-sort-order', $sort_order);
      
    }
}

Can you please confirm it helps you to fix the sort order issue for your image repeating field.

More info:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

#2625941

Thanks Minesh!
That little snippet resolves the issue perfectly for now.
Will keep an eye out for future updates.
Much appreciated!
Rita