Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    for now I using a query to get the data, but if possible please let know if there is a better idea. I am doing roughly something like..

    SELECT wp_posts.ID as answer_id, wp_posts.guid as answer_uri, wp_posts.post_title as answer_title, wp_postmeta.meta_value as question_id FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND wp_posts.post_author IN ( $user_id ) AND wp_posts.post_type = 'dwqa-answer' AND wp_posts.post_status IN ( 'publish', 'private' ) ORDER BY wp_posts.post_date DESC

    and I believe there must be a better way to do it.

    Plugin Author DesignWall

    (@designwall)

    Hi Prafulla Kumar Sahu,

    Thank you for getting in touch with us. I will announce this issue to the technical team for a check.

    If you encounter any problem, please do not hesitate to get back to us. We’re here to help you.

    Plugin Author DesignWall

    (@designwall)

    Hi Prafulla Kumar Sahu,

    Please read these lines below as our assistance:

    You can go to wp-content/themes/<your-theme-folder> and add this code in to functions.php

    add_filter( 'dwqa_prepare_archive_posts', 'dwqa_refilter_question' );
    function dwqa_refilter_question( $args ) {
     // change 0 to page id you had place other archive page contain shortcode [dwqa-list-questions]
     if ( is_page( 0 ) ) {
      $answer_args = array(
       'post_type' => 'dwqa-answer',
       'posts_per_page' => 5,
       'post_status' => 'publish',
       'fields' => 'ids',
       'no_found_rows' => true,
       'update_post_term_cache' => false,
       'update_post_meta_cache' => false,
       'author' => get_current_user_id(),
       'orderby' => 'date'
      );
    
      // this will return array with 5 answer's ids
      $answers = get_posts( $answer_args );
      $question_lists = array();
    
      foreach( $answers as $answer_id ) {
       $question_lists[] = get_post_meta( $answer_id, '_question', true );
      }
    
      $args['post__in'] = $question_lists;
     }
    
     return $args;
    }
    

    If you encounter any problem, please do not hesitate to get back to us. We’re here to help you.

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    thank you so much for your reply, what I did is created a widget where I want to display the links and there will be a “more..” link to archive page that will display all the questions the user has replayed and I was considering all users as I am adding the widget in single page . so I modified the snippet to make it something like

    function dwqa_refilter_question( $args = null, $number_of_post = 5, $user = get_current_user_id() ) {
     // change 0 to page id you had place other archive page contain shortcode [dwqa-list-questions]
     //if ( is_page( 0 ) ) {
    
      $answer_args = array(
       'post_type' => 'dwqa-answer',
       'posts_per_page' => $number_of_post,
       'post_status' => 'publish',
       'fields' => 'ids',
       'no_found_rows' => true,
       'update_post_term_cache' => false,
       'update_post_meta_cache' => false,
       'author' => $user,
       'orderby' => 'date'
      );
    
      // this will return array with 5 answer's ids
      $answers = get_posts( $answer_args );
      $question_lists = array();
    
      foreach( $answers as $answer_id ) {
       $question_lists[] = get_post_meta( $answer_id, '_question', true );
      }
    
      $args['post__in'] = $question_lists;
     //}
    
     return $args;
    }

    no I can provide it the number of post it will return and also the user id for which it will return the questions. now I would like to add my own archive page to display all the questions links the user has answered for which I have already created a separate thread .

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    and please let me know if you think I could have done it in a better way, I would love to learn .

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    Now I changed it to

    function dwqa_refilter_question( $args = null ) {
      if ( isset( $args ) ){
        $posts_per_page = isset( $args['posts_per_page'] ) ?  $args['posts_per_page'] : 5;
        $user = isset( $args['user'] ) ?  $args['user'] : get_current_user_id();
      }
     // change 0 to page id you had place other archive page contain shortcode [dwqa-list-questions]
     //if ( is_page( 0 ) ) {
      $answer_args = array(
       'post_type' => 'dwqa-answer',
       'posts_per_page' => $posts_per_page,
       'post_status' => 'publish',
       'fields' => 'ids',
       'no_found_rows' => true,
       'update_post_term_cache' => false,
       'update_post_meta_cache' => false,
       'author' => $user,
       'orderby' => 'date'
      );
    
      // this will return array with 5 answer's ids
      $answers = get_posts( $answer_args );
      $question_lists = array();
    
      foreach( $answers as $answer_id ) {
       $question_lists[] = get_post_meta( $answer_id, '_question', true );
      }
    
      $args['post__in'] = $question_lists;
     //}
    
     return $args;
    }

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    making it like echo do_shortcode("[dwqa-list-questions number=5, author=" . $post->post_author . " ]");

    but it does not work with the arguments I am passing ??

    Plugin Author DesignWall

    (@designwall)

    Hello Prafulla Kumar Sahu,

    Thanks for noticing us. We will implement this feature in the upcoming version of DW Q&A.

    However, until then you can only use dwqa_prepare_archive_posts filter to change the arguments.

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    thank you for letting me know that.

    Plugin Author DesignWall

    (@designwall)

    You’re welcome, my friend. =))

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to display links to questions the specified user has answer recently ?’ is closed to new replies.