在多次搜索失败后,我希望这里的人能帮助我。我正在使用高级自定义字段(我假设大多数人都很熟悉)从前端创建帖子。我想验证一个字段,并确保在将任何内容保存到数据库之前有一个值。
我有这个函数,但我检查的两个元数据总是返回false(可能是因为元数据还没有保存?)在保存帖子之前,我不知道如何检查它们。感谢您的任何提示。谢谢
//Create new Custom Design post from frontend
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != \'new\' )
{
return $post_id;
}
if (get_post_meta($post_id, \'upload_image\', true) || get_post_meta($post_id, \'submit_link\', true)) {
// Create a new post
global $current_user;
get_currentuserinfo();
$title = $current_user->user_email.\'-\'.get_date();
$post = array(
\'post_status\' => \'publish\' ,
\'post_title\' => $title,
\'post_type\' => \'custom-designs\' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST[\'return\']
$_POST[\'return\'] = add_query_arg( array(\'post_id\' => $post_id, \'submitted\' => \'true\', \'custom-error\' => false), $_POST[\'return\'] );
// return the new ID
return $post_id;
} else {
wp_redirect(add_query_arg(array(\'custom-error\' => \'true\'), $_POST[\'return\']));
exit;
}
}
add_filter(\'acf/pre_save_post\' , \'my_pre_save_post\' );