After much unsuccessful searching, I'm hoping someone here can help me out. I am using Advanced Customs Fields (I assume most people are familiar) to create a post from the front end. I want to validate a field, and make sure there is a value before I save anything to the database.
I have this function, but the two meta values I'm checking always return false (possibly because the meta values haven't been saved yet?) and I can't figure out how to check them before saving the post. Any tips appreciated. Thanks.
//Create new Custom Design post from frontend
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
if (get_post_meta($post_id, 'upload_image', true) || get_post_meta($post_id, 'submit_link', true)) {
// Create a new post
global $current_user;
get_currentuserinfo();
$title = $current_user->user_email.'-'.get_date();
$post = array(
'post_status' => 'publish' ,
'post_title' => $title,
'post_type' => 'custom-designs' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id, 'submitted' => 'true', 'custom-error' => false), $_POST['return'] );
// return the new ID
return $post_id;
} else {
wp_redirect(add_query_arg(array('custom-error' => 'true'), $_POST['return']));
exit;
}
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );