jeudi 29 janvier 2015

advanced custom fields plugin last input field in new posts


I have a problem with front end update on post + advanced custom fields plugin it does not clear the input on new post. It does insert or update the form correctly but when you got there for first time you see the last input things in the fields from the acf plugin. I have search for the problem and i have found one post which suggest to properly filter the $post_id i have try that too.



<?php
acf_form_head();

if ( is_user_logged_in() ) {
$current_post = isset($_GET['post'])?intval($_GET['post']):'';

if($_POST)
{
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'pending'
);
if($current_post)
{
$post_information['ID'] = $current_post;
}
$post_id = wp_insert_post( $post_information );
$_POST['return'] = add_query_arg( array('post' => $post_id), $_POST['return'] );
//print_r($current_post);
//exit();
}
?>
<?php get_header(); ?>
<?php
if($current_post)
{
?>
<?php
$query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => '-1','page_id'=>$current_post ) ); ?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
$title = get_the_title();
$content = get_the_content() ?>

<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
<?php }
else
{
$title = '';
$content = '';
}
?>
<main role="main">
<!-- section -->

<section>
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle">
<?php _e( 'Post\'s Title:', 'framework' ); ?>
</label>
<input type="text" name="postTitle" id="postTitle" value="<?php echo $title; ?>" class="required" />
</fieldset>
<?php if ( $postTitleError != '' ) { ?>
<span class="error"><?php echo $postTitleError; ?></span>
<div class="clearfix"></div>
<?php } ?>
<fieldset>
<label for="postContent">
<?php _e( 'Post\'s Content:', 'framework' ); ?>
</label>
<textarea name="postContent" id="postContent" rows="8" cols="30"><?php echo $content; ?></textarea>
</fieldset>
<fieldset>
<?php wp_dropdown_categories(""); ?>
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php $args = array(
/*'post_id' => 'new_post',*/
'field_groups' => array( 19 )
);

acf_form( $args ); ?>
</fieldset>
</form>




Aucun commentaire:

Enregistrer un commentaire