I am trying to set up a form within a custom post type that creates a new post of another post type and passes on custom fields from the first to the second. This I have working apart from the relationship fields.
I am pulling the title of a third post type in a relationship field into a hidden field in the form like this:
<?php
$posts = get_field('client');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<input type="hidden" name="client" value="<?php the_title(); ?>" />
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
The new post is then created with wp_insert_post() and the text fields added using update_field(). For populating the relationship fields I think I need to use an array but I can’t work out how. Something like:
$client = array($_POST['client'] => the_title() );
update_field( 'field_xxx', $client, $pid );
There are a few posts on here that brush on this but I can’t find any clear answers.
Hello,
did you try to hook on :
add_filter('acf/save_post' , 'your_save_post_function', 10, 1 );
and update your field into the function ?