dsmvqp3124
2016-07-02 05:53
浏览 4
已采纳

Wordpress:如何在wordpress中获得自定义元?

For every blog post I need to show the custom meta guest_author, if that is not set then default user.

This is what I want to do in PHP, please help

If guest_author is available echo guest_author else echo author

图片转代码服务由CSDN问答提供 功能建议

对于我需要显示自定义元guest_author的每篇博文,如果未设置,则为默认用户。

这就是我想用PHP做的,请帮忙

如果guest_author可用 echo guest_author else echo author

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzhao6584 2016-07-03 09:15
    已采纳

    This is what I ultimately did:

    <span class="post-info-text"><?php echo 'This interview was taken by: </span> <span class="author-name vcard fn author" itemprop="name">'; ?>
    <?php $guest_author = get_post_meta(get_the_ID(), 'guest_author', true);
    if (!$guest_author){the_author_posts_link();}else{echo $guest_author;} ?></span>
    
    打赏 评论
  • duanhuiuw12555 2016-07-02 06:14

    You can use something like:

    $userID = the_author_meta( 'ID' );
    if ($userID!= 0) //0 is for admin author id
       {
         get_the_author_meta( '/*what ever you want to get */' )
         }
    else
    {
      //The else part for the default admin author.
    }
    

    Reference:https://codex.wordpress.org/Function_Reference/the_author_meta

    打赏 评论

相关推荐 更多相似问题