[英]Trying to assign Wordpress post on user when registers
I'm currently working on a counselling website. 我目前正在咨询网站上。 My current issue I am having is getting WordPress to assign a wordpress post to a user when they register.
我当前遇到的问题是让WordPress在用户注册时向用户分配一个wordpress帖子。
1) user clicks on link, this then takes them to the wordpress register page(standard wordpress register). 1)用户单击链接,然后将他们带到wordpress寄存器页面(标准wordpress寄存器)。
link build up "wp-login.php?action=register&post=4150"
链接建立
"wp-login.php?action=register&post=4150"
2) once they're register I look on the post itself, and the author is still admin. 2)一旦注册,我就会查看帖子本身,而作者仍然是管理员。
My code: 我的代码:
function on_user_register( $user_id ) {
$id = $_GET['post'];
$post = get_post($id);
if($id){
$update_creator = array(
'ID' => $id, //created post ID
'post_author' => $user_id
);
wp_update_post( $update_creator );
}
}
add_action( 'user_register', 'on_user_register', 10, 1 );
My immediate guess is that the $_GET
variable is getting removed when the user submits the page because it is submitting the form using POST
. 我的直接猜测是,用户提交页面时
$_GET
变量将被删除,因为它是使用POST
提交表单的。 You'll need to either modify the registration form to submit your variable to the form, or find another mechanism of bringing the information over (sessions? cookies? etc) 您将需要修改注册表单以将变量提交给表单,或者找到另一种将信息传递过来的机制(会话,Cookie等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.