I am having trouble returning the values entered on my front end form to create a new post in Wordpress with the Advanced Custom Fields plugin. I have created a new field group and the form shows up fine on the front end, when I submit the form it submit with no title even though I have a title in the title box. This is a text box I have in my field group with the name of 'title'.
According to the documentation I should be able to pass a $_POST variable but am having a tough time getting it to work or finding the $_POST variable.
Here is my page template which shows the form, creates a post but the post doesnt have a title. So in a nutshell Im not sure how to retrieve the values to use in wp_insert_post:
<?php acf_form_head(); ?>
<?php get_header(); ?>
<?php
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => $_POST['fields']['title'] ,
'post_type' => 'custom_gallery' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-12 clearfix" role="main">
<?php
acf_form(array(
'field_groups' => array('31056'),
'post_id' => 'new',
'submit_value' => 'Submit Project'
)); ?>
</div> <!-- end #main -->
<?php //get_sidebar(); // sidebar 1 ?>
</div> <!-- end #content -->
<?php get_footer(); ?>