php 如何在WordPress中获取帖子作者姓名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42871987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:43:25  来源:igfitidea点击:

How to get post author name in WordPress?

phpmysqlwordpresspostshook-wordpress

提问by Rakhi Prajapati

In WordPress I need to fetch name of author who created post using author_id.
How can I find author_name?

在 WordPress 中,我需要获取使用author_id.
我怎样才能找到author_name

回答by Raunak Gupta

You can use get_the_author_meta(), to get author data.

您可以使用get_the_author_meta(), 来获取作者数据。

echo get_the_author_meta('display_name', $author_id);

Hope this helps!

希望这可以帮助!

回答by Amit

This should work like charm

这应该像魅力一样工作

<?php echo get_the_author(); ?>

For more detailed information. https://codex.wordpress.org/Function_Reference/get_the_author

如需更多详细信息。 https://codex.wordpress.org/Function_Reference/get_the_author

回答by Nikhil Chopde

Use below code in single.php or the relevant page you want author name

在 single.php 或您想要作者姓名的相关页面中使用以下代码

<?php get_the_author_meta( 'display_name', $author_id ); ?>

回答by Jawwad Rizwan

Add This code in single-post.php

在 single-post.php 中添加此代码

<?php echo get_the_author(); ?>

I hope this will work !!

我希望这会奏效!!