WordPress 如何获取文章发表用户ID

WordPress插件/主题开发中,如何获取文章发表用户的ID ?

LOOP循环中

官方文档:

get_the_author_meta( string $field = '', int|false $user_id = false )

Retrieves the requested data of the author of the current post.

Description 

Valid values for the $field parameter include:

  • admin_color
  • aim
  • comment_shortcuts
  • description
  • display_name
  • first_name
  • ID
  • jabber
  • last_name
  • nickname
  • plugins_last_view
  • plugins_per_page
  • rich_editing
  • syntax_highlighting
  • user_activation_key
  • user_description
  • user_email
  • user_firstname
  • user_lastname
  • user_level
  • user_login
  • user_nicename
  • user_pass
  • user_registered
  • user_status
  • user_url
  • yim

Parameters

$field

(string) (Optional) The user field to retrieve.

Default value: ”$user_id

(int|false) (Optional) User ID.

Default value: false

Return

(string) The author’s field from the current author’s DB object, otherwise an empty string.

在循环外面通过以下方法获取用户ID

$author_id = get_post_field ('post_author', get_the_ID() );

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

WordPress 如何获取文章发表用户ID

`微信`扫码 加好友

链接到文章: https://gkxyz.com/wordpress-ruhehuoquwenzhangfabiaoyonghuid.html

推荐站点

评论已关闭