ID author of the best answer

7.03K viewsGeneral
0

I need to pull in the template file ID of the author of the best answer how to do it?

Answered question

Sorry I am not able to understand. You want user ID of best answer?

0

$thispost_id=$post->ID;
$best_answer = ap_selected_answer( $thispost_id );
$answer = get_post( $best_answer );
$author_id_best = $answer->post_author;

Answered question
0

Since 4.0, you can do this:

$best_answer = ap_selected_answer( 23 ); // Replace number with question id.
$answer = get_post( $best_answer );
$author_id = $answer->post_author;

Posted new comment

If there is no better answer then the result is 1. Why?

Do a answer recount from AnsPress options -> tools.

It does not help. Are there any other ways to get a user ID with the best answer?

Please share your code

Hello Just checked this function and never returns 1 if no answer selected. Please try updating to development version. Or contact me by email with temporary credentials.

I noticed that if there is no better answer, then the ID of the author of the post is shown