Love the plugin, but I’m having an issue retrieving a field using the save_post functionality.
What I’m attempting to do is grab a field from a front-end form when it gets submitted and save it as a variable for post_title. This forum post seemed to be the answer to my problem but for some reason I can’t get it to work: http://support.advancedcustomfields.com/forums/topic/need-help-with-save_post-hook/
Here’s the code I’m using:
<?php
add_action('acf/save_post', 'retrieveEventName', 20);
function retrieveEventName( $post_id )
{
$eventName = get_field('name_of_event', $post_id);
}
?>
<?php
$args = array(
'post_title' => $eventName,
'post_type' => 'post',
'post_status' => 'draft',
'post_category' => array(9),
'comment_status' => 'closed'
);
acf_form(array(
'post_id' => 'new_post',
'form' => true,
'new_post' => $args,
'submit_value' => 'Create a new event'
));
?>
I feel like there’s probably something really simple I’m overlooking. Thanks in advance for any help.
Hi @nhall
Thanks for the code. I’ve just tested it and can confirm that it works.
Can you please debug your function to double check that the value is being found?
echo '<pre>';
print_r($eventName);
echo '</pre>';
die;