1

I insert author box below my post and use get_the_author to return author name but it doesn't working. It also doesn't working with Search post by author. Hope everyone give me solution, thank in advance.

enter image description here

1
  • Is this code inside a proper Loop?
    – s_ha_dum
    Feb 7, 2014 at 17:55

3 Answers 3

5

Echo it out... <?php echo get_the_author(); ?>

0
6

Though echoing worked for the OP, the issue could be related to setting up the post manually, as was in my case. Here is the code:

$post = get_post();
setup_postdata($post);    // setting up the post manually

// Then you can fetch/echo the author name
var $authorName = get_the_author(); 
var $content    = get_the_content();   // This works too
0

As a general rule, any WP function beginning with get_ will return the result rather than echoing it. There's usually a corresponding function - in this case it's the_author() - which will echo it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.