Php acf_form()验证和反馈
我正在使用以下代码创建一个用于提交新帖子的前端表单(我希望你们大多数人都熟悉它):Php acf_form()验证和反馈,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在使用以下代码创建一个用于提交新帖子的前端表单(我希望你们大多数人都熟悉它): $options = array( 'post_id' => 'new_post', 'new_post' => array( 'post_type' => 'post', 'post_status' => 'pending' ), 'html_before_fields' => $html_bef
$options = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'post',
'post_status' => 'pending'
),
'html_before_fields' => $html_before_fields,
'html_after_fields' => $html_after_fields,
'uploader' => 'basic',
'submit_value' => __("Create", 'domain'),
'updated_message' => __("Your post was submitted successfully! Please wait for it to be approved.", 'domain'),
);
acf_form($options);
这里是myfunctions.php的一个片段
function _action_ssd_acf_submit_post_pre_save( $post_id ) {
if( empty($_POST['acf']) ) {
return;
}
if ( !isset($_POST['acf_post_submit']) ) { // this is a hidden input field in the form
return;
}
if ( ) { // some more checks here
wp_mail(); //removed parameters for cleaner code, I send email to the admin
}
if( empty(get_user_meta(get_current_user_id(), 'this_user_can_submit', true)) ) {
exit;
return;
}
}
add_action( 'acf/pre_save_post', '_action_ssd_acf_submit_post_pre_save' );
如何阻止帖子保存,因为它总是保存为草稿
此外,当提交时出现错误时,我似乎无法找到更改update\u消息的方法。例如,如果用户没有所需的user\u meta
所以,是的,我的问题是,我无法停止提交帖子(在验证错误的情况下),并在页面刷新后发送前端消息反馈。如果您希望发布帖子,则不能将其设置为草稿,您需要使用'post\u status'=>'publish'
而不是'post\u status'=>'post'
如果您希望发布文章,而不是将其设置为草稿,您需要使用'post\u status'=>'publish'
而不是'post\u status'=>'post'
,我在这里写代码时犯了一个错误。Post status“Post\u status”=>“Post”
是上面应该写的。我的问题是,在页面刷新后,我无法停止提交帖子(在验证错误的情况下)并发送前端消息反馈。我在这里编写代码时犯了一个错误。Post status“Post\u status”=>“Post”
是上面应该写的。我的问题是,我无法停止提交帖子(在验证错误的情况下),并在页面刷新后发送前端消息反馈。