【问题标题】:ACF not saving data and only showing spinner from front side wordpressACF 不保存数据,只显示来自前端 wordpress 的微调器
【发布时间】:2016-02-10 12:46:10
【问题描述】:

我已经在前端显示了 ACF 表单,现在尝试保存数据,但它正在旋转加载而不是保存帖子。我正在尝试下面的代码。我做错了什么

<?php

add_action( 'get_header', 'tsm_do_acf_form_head', 1 );
function tsm_do_acf_form_head() {
    // Bail if not logged in or not able to post
    if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
        return;
    }
    acf_form_head();
}
add_shortcode( 'intake_form', 'intake_form_open' );
function intake_form_open($atts) {

// Bail if not logged in or able to post
    if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
        echo '<p>You must be a registered author to post.</p>';
        return;
    }
?> 
    <div id="personal-information">

        <?php

        $edit_post = array(
            'post_id'            => 'new', // Create a new post
        // PUT IN YOUR OWN FIELD GROUP ID(s)
            'field_groups'       => array($atts['id']), // Create post field group ID(s)
            'form'               => true,
            'return'             => '%post_url%', // Redirect to new post url
            'html_before_fields' => '',
            'html_after_fields'  => '',
            'submit_value'       => 'Submit Post',
            'updated_message'    => 'Saved!'
        );
        acf_form( $edit_post );
        ?>

    </div>
<?php

}

add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post', 10, 2 );
function tsm_do_pre_save_post( $post_id ) {
    // Bail if not logged in or not able to post
    if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
        return;
    }
    // check if this is to be a new post
    if( $post_id != 'new' ) {
        return $post_id;
    }
    // Create a new post
    $post = array(
        'post_type'     => 'post', // Your post type ( post, page, custom post type )
        'post_status'   => 'private', // (publish, draft, private, etc.)
        'post_title'    => 'Comments ACF Form', // Post Title ACF field key
        'post_content'  => $_POST['acf']['field_56badad4fb425'], // Post Content ACF field key
    );
    // insert the post
    $post_id = wp_insert_post( $post );
    // Save the fields to the post
    do_action( 'acf/save_post' , $post_id );
    return $post_id;
}

?>

【问题讨论】:

    标签: php wordpress save advanced-custom-fields


    【解决方案1】:

    ACF 或其他一些插件在后端引发错误。在 wordpress 中打开调试,并检查错误日志以查找问题。

    请检查以确保您没有启用任何其他前端页面发布插件。当 WP 前端插件也启用时,我也遇到了同样的问题。

    一旦我禁用它,一切正常。

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      相关资源
      最近更新 更多