最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - how to display author name in custom post type

programmeradmin0浏览0评论

What should write for display_name? I want to display author name in custom post types, but I got administrater name ‘root’ for get_the_author() function and when I used get_the_auther_meta(), I couldn’t get anything. If anyone knows please let me know.

What should write for display_name? I want to display author name in custom post types, but I got administrater name ‘root’ for get_the_author() function and when I used get_the_auther_meta(), I couldn’t get anything. If anyone knows please let me know.

Share Improve this question asked Dec 1, 2020 at 4:50 vishalvishal 231 gold badge2 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

What I did wrong is, I forget to get author box, hence the_author function was not working, so I add this code in functions.php file

    add_post_type_support( 'my_post_type', array(
    'author', 'excerpt',
    ) );

then I got author box and in author box, set author name and add this code in custom post file

   the_author();

or

    echo get_the_author_meta('display_name');
发布评论

评论列表(0)

  1. 暂无评论