Php 通过前端帖子提交根据条件设置帖子作者

Php 通过前端帖子提交根据条件设置帖子作者,php,wordpress,Php,Wordpress,我使用wordpress cms,我允许用户从前端发帖。有三种类型的用户。我自己是管理员,一名初级管理员,角色是作者,任何来自公众的人都是未登录用户。当前,如果有任何未登录的用户从前端发帖,我将被指定为具有此代码的作者。当前,我的wp_insert_post数组如下所示: 'post_title' => $final_title, 'post_content' => $about_stuff, 'post_status' => 'draft', 'post_auth

我使用wordpress cms,我允许用户从前端发帖。有三种类型的用户。我自己是管理员,一名初级管理员,角色是作者,任何来自公众的人都是未登录用户。当前,如果有任何未登录的用户从前端发帖,我将被指定为具有此代码的作者。当前,我的wp_insert_post数组如下所示:

'post_title'    => $final_title,
'post_content'  => $about_stuff,
'post_status'   => 'draft',
'post_author'   => '20',
'post_type' => 'post',
 etc....
其中,我的作者id为“20”。这一切都很好。现在,我想实现的是,当我的小朋友登录并在前端创建帖子时,我希望他成为帖子的作者,而不是像现在这样的我。我知道post_作者需要是一个可变示例$content_创建者。下面是我到目前为止所写的代码,但我不知道如何将其组合起来以实现我所需要的。具体来说,我很困惑如何使变量$content\u creator与其余代码一起工作

if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
    if ( 19 == $current_user->ID ) {
    'post_author' => '19';
    } else {
    'post_author' => '20',
    }
 } 
代码非常简单,说明如下:检查用户是否登录,如果是,检查用户id。如果用户id等于19,则设置“post_author”=>“19”我的下级用户id,否则将作者设置为管理员。我想问的两件事是,在我的代码之前是否还需要global$post,以及是否应该使用另一个过滤器。请帮忙


最后一个场景必须是,当管理员或其他人创建帖子时,帖子作者必须设置为admin me,但当我的下级创建帖子时,他必须设置为帖子作者。如果我们在后端创建帖子,这是不必要的,但由于某些原因,我们更喜欢在前端创建帖子。

事实证明,使用wp\u update\u post非常简单。尽管如此,现在它运行良好。如果你发现什么有趣的事,请告诉我。这是我在wp_insert_post之后使用的代码,没有对数组进行任何更改

if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
    if ( 19 == $current_user->ID ) {

    $update_creator = array(
                'ID'          => $pid, //created post ID
                'post_author' => '19'
            );

    wp_update_post( $update_creator );
    }
}