我已经在正面显示了ACF表单,现在正试图保存数据,但它正在旋转加载而不是保存posts.I我正在尝试下面的代码。我做错了什么
<?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;
}
?>
答案 0 :(得分:0)
ACF或其他一些插件在后端引发错误。在wordpress中打开Debug,并检查错误日志中的问题。
请检查以确保您没有启用任何其他前端页面发布插件。当WP Front端插件也被启用时,我遇到了同样的问题。
一旦我禁用它,一切正常。