template.php:
<?php /* Template Name: PostYourPrice */ ?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<?php $acf = array(
'post_id' => 'new',
'field_groups' => array(20),
'submit_value' => 'Submit'
); ?>
<?php acf_form($acf); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
function.php:
/* front-end post */
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'wp-admin' );
}
/* more */
function my_pre_save_post( $post_id ) {
if ( $post_id != 'new' ) {
return $post_id;
}
$post = array(
'post_status' => 'draft',
'post_title' => $_POST['fields']['field_55068a7990cc3'],
'post_type' => 'events'
);
$post_id = wp_insert_post($post);
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
?>
/* front-end post */
/* featured image */
<?php
function acf_set_featured_image( $value, $post_id, $field ){
if($value != ''){
//Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta($post_id, '_thumbnail_id', $value);
}
return $value;
}
// acf/update_value/name={$field_name} - filter for a specific field based on it's name
add_filter('acf/update_value/name=field_55036c9ec441e', 'acf_set_featured_image', 10, 3);
?>
/* featured image */
Featured image part doesn’t work either. I would greatly appreciate any help!
Refering to ACF doc (http://www.advancedcustomfields.com/resources/acf_form/), your post_id value should be set to new_post :
<?php $acf = array(
'post_id' => 'new_post',
'field_groups' => array(20),
'submit_value' => 'Submit'
); ?>
Hi @tanz1r,
Thanks for the post.
Yes you can make use of the ‘new_post’ argument but please note that this is only available in the Pro version of the plugin.
I have tried this code on my end and it works:
function my_pre_save_post( $post_id ) {
if ( $post_id !== 'new' ) {
return $post_id;
}
$post = array(
'post_status' => 'draft',
'post_title' => $_POST['fields']['field_55068a7990cc3'],
'post_type' => 'events'
);
$post_id = wp_insert_post($post);
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );