使用ACF从前端表单返回值


Return Values from front end form using ACF

我在返回在前端表单上输入的值以使用高级自定义字段插件在Wordpress中创建新帖子时遇到问题。我创建了一个新的字段组,表单在前端显示得很好,当我提交表单时,它没有标题,即使我在标题框中有标题。这是我的字段组中的一个文本框,名称为"title"。

根据文档,我应该能够传递$_POST变量,但很难让它工作或找到$_POST变量。

这是我的页面模板,它显示了表单,创建了一个帖子,但帖子没有标题。因此,简而言之,我不确定如何检索要在wp_insert_post:中使用的值

<?php acf_form_head(); ?>
<?php get_header(); ?>
<?php 
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']['title'] ,
        'post_type'  => 'custom_gallery' ,
    );  
    // insert the post
    $post_id = wp_insert_post( $post ); 
    // update $_POST['return']
    $_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' );
?>
            <div id="content" class="clearfix row">
                <div id="main" class="col-sm-12 clearfix" role="main">
                    <?php 
                    acf_form(array(
                        'field_groups'        => array('31056'),
                        'post_id'       => 'new',
                        'submit_value'      => 'Submit Project'
                )); ?>
                </div> <!-- end #main -->
                <?php //get_sidebar(); // sidebar 1 ?>
            </div> <!-- end #content -->
<?php get_footer(); ?>

尝试使用以下方法:https://wordpress.org/plugins/forms-actionshttps://wordpress.org/plugins/acf-frontend-display

表单操作处理您发送的表单并执行操作。