簡體   English   中英

自動為每個用戶創建一個帖子並為其分配一個模板

[英]Automatically create a post for every user and assign a template to it

我正在嘗試讓 wordpress 為每個用戶創建新頁面或發布新頁面並為其分配給定模板。 它按預期創建帖子/頁面,但不附加任何模板。 關於這如何提供幫助的任何想法。 我的代碼如下所示。

function my_create_page($user_id){
    $the_user = get_userdata($user_id);
    $new_user_name = $the_user->user_login;
    $my_post = array();
    $my_post['post_title'] = $new_user_name;
    $my_post['post_type'] = 'page';
    $my_post['post_content'] = '';
    $my_post['post_status'] = 'publish';
    $my_post['post_theme'] = 'user-profile';
    wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php');

你只缺少一行:

function my_create_page($user_id){
    $the_user = get_userdata($user_id);
    $new_user_name = $the_user->user_login;
    $my_post = array();
    $my_post['post_title'] = $new_user_name;
    $my_post['post_type'] = 'page';
    $my_post['post_content'] = '';
    $my_post['post_status'] = 'publish';
    $my_post['post_theme'] = 'user-profile';

    $my_post['page_template'] = 'name-of-template.php';

 wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php'); 

法典:wp_insert_post

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM