1

i use advance custom field for add post from users on home screen , after user click on submit button ,The text is recorded in the database and wordpress but user redirected to a blank page with same url

<?php
/*
Template Name: new post
*/
?>

<?php acf_form_head(); ?>
<?php get_header(); ?>
 
<div class="large-back-bg4"><div class="index-small">
<div class="breadcrumb"><?php sitralweb_breadcrumbs(); ?></div>
<div class="single-right-content">
    



    <?php acf_form(array(
        'post_id'       => 'new_post',
        'new_post'      => array(
            'post_type'     => 'state',
            'post_status'   => 'pending'
        ),
        'submit_value'  => 'Send it',
        'return' => 'http://khorsandmelk.ir/'
    
        


    )); ?>
    






</div>
</div>
</div>

<?php get_footer(); ?>

Debug_log :

Function create_function() is deprecated in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-all-import-pro2/classes/config.php on line 47

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_meta_boxes' not found or invalid function name in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-includes/class-wp-hook.php on line 287

Notice: Undefined offset: 0 in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-parsidate/includes/fixes-permalinks.php on line 246

Notice: Undefined offset: 1 in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-parsidate/includes/fixes-permalinks.php on line 247

Notice: Undefined offset: 2 in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-parsidate/includes/fixes-permalinks.php on line 248

Warning: Cannot modify header information - headers already sent by (output started at /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-all-import-pro2/classes/config.php:47) in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-includes/pluggable.php on line 1281

Warning: Cannot modify header information - headers already sent by (output started at /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-content/plugins/wp-all-import-pro2/classes/config.php:47) in /home2/khorsand/domains/khorsandmelk.ir/public_html/wp-includes/pluggable.php on line 1284

Sina Cena
  • 11
  • 2
  • I don't quite understand why you would put an ACF form into the post-loop. If there are 10 posts on the current page, you'd end up with 10 forms for creating a new post - is that what you want? Other than that, you can use the `'return' => 'target URL here'` option to specify where you want to be redirected after the form was submitted. How do you want it to work for the user? Also, you should check the DEBUG_LOG for information on whether some error occurred. – Damocles Aug 03 '20 at 14:57
  • thanks ,I made the changes but the problem still exists, I add debug details – Sina Cena Aug 03 '20 at 15:52

1 Answers1

2

The "headers already sent" issue with ACF and acf_form is very common and can happen because of a lot of reasons - especially when the text is being output before <?php tag.

Instead of debugging it case-to-case, try updating the following in your functions.php file:

function add_acf_form_head() {
    acf_form_head();
}
add_action( 'wp_head', 'add_acf_form_head', 1 );

The priority "1" is very important here, and in most of the cases - it is the magic sauce that you're looking for.

Suraj Lulla
  • 489
  • 5
  • 12