Home › Forums › Front-end Issues › Post Doesn't Publish From Front End. Checked many times.
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' );
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.
— Advanced Custom Fields (@wp_acf) January 6, 2023
https://t.co/HahJUCcyH4
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.