Home › Forums › Front-end Issues › Creation and edition of a post › Reply To: Creation and edition of a post
And now ? it is working perfectly !
<?php
/**
* Template Name: Page Creation Vigneron3.0 2
*/
?>
<?php
// fonction ACF --------------------------------------------
// with this i dont have to think to put acf_form_head whereever I need it, it is always there
add_action('wp_head','acf_form_head');
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']['field_5640802e05f78'],
'post_content' => $_POST['fields']['field_5640802e05f79'],
'post_type' => 'page' ,
'page_template' => 'page_vigneron30.php',
);
// insert the post
$post_id = wp_insert_post( $post );
$_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' );
function my_acf_save_post( $post_id ) {
// Don't do this on the ACF post type
if ( get_post_type( $post_id ) == 'acf' ) return;
// Get the Fields
$fields = get_field_objects( $post_id );
// Grab Post Data from the Form
$post = array(
'ID' => $post_id,
'post_title' => $fields['titre']['value'],
'post_content' => $fields['contenu']['value'],
);
// Update the Post
wp_update_post( $post,true );
}
add_action( 'acf/save_post', 'my_acf_save_post', 10, 1 );
?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<?php
$args = array(
'post_id' => 'new',
'post_title' => false,
'post_content' => false,
'field_groups' => array( 5015 ),
'submit_value' => "Valider cette nouvelle action"
);
acf_form( $args );
?>
</div><!-- #primary -->
<?php get_footer(); ?>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.