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!