【发布时间】:2018-02-07 14:50:08
【问题描述】:
当用户创建自定义帖子类型时,作者字段似乎没有传递回 WP 帖子功能。
正如标题所说,我正在以编程方式创建一个用户帐户,并让该用户登录并撰写自定义post_type = 'job' 的帖子。
这一切在数据库中看起来都很好 - 用户和帖子已插入。 post_author 确实与创建它的用户的ID 相同。
但是,在“用户帐户”面板中,该用户的帖子计数为 0,并且 API 数据对象省略了作者。我已经为其他自定义帖子类型配置了 API,并且端点可以返回除作者之外的所有帖子数据。
我也尝试使用这些用户从 CMS 创建帖子,同样,即使我授予他们管理员权限,他们的帖子计数为 0 - 帖子归因于他们的作者 ID。我也尝试过使用wp_update_post();强制和更新
这是创建用户的代码,然后是帖子:
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email_address, $password, $email_address );
//login
wp_clear_auth_cookie();
wp_set_current_user ( $user_id );
wp_set_auth_cookie ( $user_id );
// Set the role
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
//Ready data for linked post type creation
$new_post = array(
'post_content' => $email_address,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_id,
'post_title' => $post_name,
'post_name' => $post_name,
'post_type' => $user_type
);
//Create the post
$account_link_post_id = wp_insert_post($new_post);
【问题讨论】:
标签: wordpress wordpress-theming posts wordpress-rest-api author