Get_the_author doesn’t return author name

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

Related posts

3 comments

  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
    
  2. 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.

Comments are closed.