當用戶創建自定義帖子類型時,作者字段似乎不會被傳遞迴WP帖子功能。自定義帖子類型和作者不相關,用戶帖子數爲0,api不會在帖子對象中返回作者
正如標題所說,我以編程方式創建用戶帳戶,並讓該用戶登錄並寫入自定義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);