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
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.
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
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 );
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
@Rahul ?
Please tell me clearly what you are trying to do, your question is not clear to me.
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.