0

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

  • Is this code inside a proper Loop? – s_ha_dum Feb 7 '14 at 17:55
4

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

1

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, privacy policy and cookie policy

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