Display post author’ answers

5.54K viewsGeneralUser answers
0

I would like to show the answers done by the author of the current post. Is that possible? Is there a shortcode for that?

Unselected an answer
0

Hi Rahul!
Thank you for your answer! I was able to do what I was looking for. I had to make a little change in the second line of your code. Not sure if I messed up… but the results are good anyways.

global $answers;
  $user_id = get_the_author_id();
  $args['ap_current_user_ignore'] = true;
  $args['ignore_selected_answer'] = true;
  $args['showposts']              = 3;
  $args['author']                 = $user_id;
  if ( false !== $paged ) {
   $args['paged'] = $paged;
  }
  anspress()->answers = $answers = new \Answers_Query( $args );
  ap_get_template_part( 'addons/user/answers' );

However, I miss all the format that the answers show in the buddypress profile, like here:


The results are these. I have no idea on how to make it look like the one above.

What concerns me the most is the fact that the button to load more questions it is not working.
You can check it here.

Posted new comment

Its because this page is not AnsPress page hence no JS are loaded. Please make sure to enqueue “anspress-main” JS in your current page as well.

Thank you for your answer, Rahul. Although I’m not really a developer, and know nothing about coding.
If you can help me with something more specific, that’d be great. I mean like a code I can paste to functions.php, for example.
Thank you anyway!

add_action( ‘enqueue_scripts’, function () {
wp_enqueue_script( ‘anspress-main’ );
}, 999 );

I’ve tried pasting it to functions.php of my theme and in footer.php. Still not working…

0

No shortcode available but it can be done using PHP.

  global $answers;
  $user_id = ap_current_user_id();
  $args['ap_current_user_ignore'] = true;
  $args['ignore_selected_answer'] = true;
  $args['showposts']              = 10;
  $args['author']                 = $user_id;
  if ( false !== $paged ) {
   $args['paged'] = $paged;
  }
  anspress()->answers = $answers = new \Answers_Query( $args );
  ap_get_template_part( 'addons/user/answers' );

Unselected an answer