Get question author username
Try this:
$question = get_post($question_id); get_the_author_meta( 'user_login', $question->post_author );
Read more info here: get_the_author_meta
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
A just used global $question_id 🙂
I you are in question loop, then:
ap_question_get_author_id(); //get author ID ap_question_get_the_author_id(); //Echo author ID
or if not in loop then you can simply use WP function to retrieve author ID.
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
I guess I`m not in the loop, because I get this error: http://fs2.directupload.net/images/150705/kf27esh7.png
When I try to get the author ID via wordpress function, I only get the username of the admin and not of the question user
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
Here you can see, that the wordpress function does not returns the correct name: http://fs1.directupload.net/images/150717/tjqbjlmf.png
The name above the question is generated by this function:
global $post;
$a_id = $post->post_author;
echo get_the_author_meta( ‘user_nicename’ , $a_id );
Its because your are getting nice name, try this: echo get_the_author_meta( ‘display_name’ , $a_id );
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
I just analysed the $post he gets and this was the result: http://fs2.directupload.net/images/150718/8gdyhjsc.png
So I guess this is the meta of the page, that contains the “[anspress]” shortcode and not the question meta
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
@Rahul ?
Please tell me clearly what you are trying to do, your question is not clear to me.
![](https://secure.gravatar.com/avatar/cbbc849cc6bf14802f72630fb21dc361?s=30&d=https%3A%2F%2Fanspress.net%2Fwp-content%2Fuploads%2Fap_avatars%2F0336dcbab05b9d5ad24f4333c7658a0e.jpg&r=g)
Ok 🙂 Im trying to get the username of the question author outside the loop. The problem is, that when I call the $post->post_author;
function via shortcode in the “Anspress top” widget area, it returns the author name of the page that contains the [anspress]
shortcode instead of the question. You can see a var_dumb of the $post->post_author;
here: http://area51.zoker.me/freelancer/support/community/question/third-test/
But question_id is a undefined var.