我在插件中使用以下代码向WordPress MU系统添加帖子。除非超级用户尝试使用该函数,否则一切都很好。函数返回
无法将post插入数据库
$post = [
'post_content' => NULL,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'artikelregister',
'tags_input' => $keywords,
'tax_input' => [
'issue' => $issue,
'keywords' => $keywords
]
];
$insert = wp_insert_post($post);超级用户被分配到我们正在工作的页面。我没有头绪
编辑:正确的错误信息。
发布于 2016-08-22 09:23:25
在没有找到解决方案之后,我建立了一个解决办法:
我插入了一个名为“insert_user”的额外表单字段,该字段的值是用户的ID。
if(isset($_POST['insert_user']) && is_numeric($_POST['insert_user']) && is_super_admin()) {
$postAuthor = $_POST['insert_user'];
} else {
$postAuthor = get_current_user_id();
}
$post = [
'post_author' => $postAuthor,
//more arguments here ...
];
$insert = wp_insert_post($post);因此,现在SuperUser可以选择用于导入的用户ID。
https://stackoverflow.com/questions/36163466
复制相似问题