0

我正在尝试让 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');
4

1 回答 1

0

你只是少了一行:

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

于 2015-06-17T03:51:02.310 回答