dssqq64884 2015-02-18 22:15
浏览 12

自动为每个用户创建帖子并为其分配模板

I'm trying to get wordpress to create new page or post for every user and asign a given template to it. It creates the post/page as expected but doesn't attatch any template to it. Any ideas on how this can help. My code is as shown b elow.

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');
  • 写回答

1条回答 默认 最新

  • doumao1887 2015-06-17 03:51
    关注

    You're just missing one line:

    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'); 
    

    Codex: wp_insert_post

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题