WordPress获取用户ID的几种方法

追格官方小助手/ 2022年05月11日/ WordPress/ 浏览 2225

在WordPress主题开发或追格小程序中,使用ID的频率很高,今天小编介绍几种获取用户ID的方法,当然不局限于以下几种方式,还有很多其他方式也可以获取。


1、后台直接查看用户ID的方法

详见:https://www.zhuige.com/news/396.html


2、通过用户名获取用户 ID


$the_user = get_user_by('login', 'salongweb');
$the_user_id = $the_user->ID;


3、通过文章ID获取作者ID


$my_post = get_post( $post_id ); // 获取文章 ID 获取文章数据
echo $my_post->post_author; // 打印出作者 ID


4、WooCommerce 的订单中获取用户ID


$customer_id = get_post_meta( 888, '_customer_user', true); // 888 是订单 ID


5、使用get_current_user_id()函数获取用户ID


$current_user_id = get_current_user_id();


6、通过Email获取用户 ID


$the_user = get_user_by('email', 'admin@salongweb.com');
$the_user_id = $the_user->ID;


发表评论

暂无评论,抢个沙发...

客服 工单