Skip Navigation

[Resolved] Duplicate a post and the relationship

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 1 reply, has 2 voices.

Last updated by Minesh 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1419365

I'm duplicating a post from the front end.
All it's working like a charm except when copying the relationship "tablon-publicacion". I'm not able to pass de id of the parent "tablon" in the "toolset_connect_posts" line.

I'm using that code:

Form:

[code]
[credform class='cred-form cred-keep-original']
[cred_field field='form_messages' value='' class='alert alert-warning']

<!-- Here goes the rest of the form -->

<div class="form-group hidden">
<label>Parent of tablon</label>

[cred_field field='_wpcf_belongs_tablon_id' value='' urlparam='parent_tablon_id' class='form-control' output='bootstrap']
</div>
[cred_field field='form_submit' value='Guardar cambios' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
</div>
[/credform]
[/code]

functions.php

[code]
function tssupp_duplicate_post( $post_id, $form_data ) {

if ( $form_data['id'] == 193 ) { // Edit form ID;
// get data of original post
$post = get_post( $form_data['container_id'], ARRAY_A );
// update the new post with this data
$post['ID'] = $post_id;
$post['post_title'] = 'Copia de ' . $post['post_title'];
wp_update_post( $post );

// get fields of original post
$fields = get_post_meta( $form_data['container_id'] );

// update the new post with these fields
foreach ($fields as $key => $values) {
foreach ($values as $value) {

$value = maybe_unserialize( $value );

add_post_meta($post_id, $key, $value, false);
}
}

toolset_connect_posts( 'tablon-publicacion', $tablon <-- (it is not working!), $post_id);

}
}
add_action( 'cred_save_data', 'tssupp_duplicate_post', 10, 2 );
[/code]

¿Can you help me how to do it?
Thanks in advance!

#1421101

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The code you shared looks faulty and while I was reviewing it.

Can you please share the problem URL where the form is added and explain to me what relationship you want to make with what entities as well as where the code you shared is added.

*** 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.