Skip Navigation

[Closed] The code provided to insert repeatable fields works but it inserted twice

This support ticket is created 3 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
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: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#1624071
Captura.PNG

I am trying to:

function insert_dia_cerrado(  $concesionario_id, $fecha ) {
	// if "Post" exists
	if($concesionario_id) {
	
		$ppp_post = array(
			'post_title'    => $fecha,
			'post_status'   => 'publish',
			'post_author'   => 1,
			'post_type' => 'cerrado'
		);
		
		$ppp_post_id = wp_insert_post( $ppp_post );
		
		if($ppp_post_id) {
	
			update_post_meta( $ppp_post_id, 'wpcf-dia-cerrado', $fecha);
			toolset_connect_posts( 'cerrado', $concesionario_id, $ppp_post_id );
	
		}
	}
}

I got this code from: https://toolset.com/forums/topic/how-to-add-repeatable-field-values-via-code/

But when I call the function (just once), like:

insert_dia_cerrado (15, '29-05-2020');

The field is inserted, but twice (you can see attached image)

how could i prevent this?

I was thinking using post_exists but it could exists for other post.. so..

any thoughts?

#1624541

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

To better help with this issue, and to isolate it from any possible conflicts with your theme/plugins/server setup, I created a test server on our platform. Please log into it, add your code, and reproduce the issue. If it is reproduced, I'll look into it. If it is not reproduced, check on your test site if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Fourteen. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at the time to track where the incompatibility is produced.

Please check the login information in my previous private message(May 14, 2020 at 3:21 pm)

The topic ‘[Closed] The code provided to insert repeatable fields works but it inserted twice’ is closed to new replies.