我实际上希望我的用户在注册时有一个活动的用户页面。我知道WP在用户创建帖子之前不会创建作者页面,但自动发布某些内容会起作用,这不是我想要做的。
我本来打算
add_action(\'user_register\',\'create_new_user_post\');
function create_new_user_post($user_id){
if (!$user_id>0)
return;
// Create post object
$empty_post = array(
\'post_title\' => \'waste of DB space\',
\'post_content\' => \'an empty post.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id
);
// Insert the post into the database
$bio = wp_insert_post( $empty_post );
//and if you want to store the post ids in
//the user meta then simply use update_user_meta
update_user_meta($user_id,\'_bio_post\',$bio);
}
但是,仅仅为了让“作者”有一个作者页面而创建的帖子类型似乎是一种浪费。
有人能给我指出一个正确的方向,在注册时创建作者页面而不发布帖子吗?
SO网友:rz-requilel
有趣的问题,虽然我不得不说,使用会员插件解决这个问题要容易得多——我想你不会想要的。
我找到了this plugin 然而,作者已经有两年多没有更新过了。从那时起,php模板并没有太大变化。唯一的方法是在循环外查询作者或捕获404。php并显示内容;
if (!function_exists(\'show_authors_without_posts\')) {
function show_authors_without_posts($template) {
global $wp_query;
if( !is_author() && get_query_var(\'author\') && (0 == $wp_query->posts->post) ) {
// debug
// echo \'Overwrite default 404 template...\';
return get_author_template();
}
return $template;
}
add_filter(\'404_template\', \'show_authors_without_posts\');
}
Here\'s also an answered question with querying an author archive outside of the loop.