要在 WordPress 的文章內取得作者的 id,可以透過以下兩種方法:

直接執行 get_the_author_meta(),並指定要取得 ID

$author_id = get_the_author_meta('ID');

 

或是透過文章 id 去取得作者 ID

$author_id = get_post_field('post_author' , $post->ID);

 

Reference