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

    (@prafulla)

    I think it may be possible with https://localhost/mysite/questions/?user= not+user_name&filter=my-subscribes but how to make it !user_name and how to retrieve his own questions for which he has posted answer that will be a problem . again it seems multiple filters are not allowed . ??

    but again it seems
    EDIT
    https://localhost/mysite/question/?filter=my-subscribes&sort=answers is allowed

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    This can be done by applying filter
    dwqa_prepare_archive_posts

    and modifying the query and another way can be overriding

    add_action( 'dwqa_before_questions_list', array( $this, 'prepare_archive_posts' ) );

    but the first one is better and I would recommend .

    it will be

    add_filter( 'dwqa_prepare_archive_posts', function( $query ){
       //  return modified query
       $query =  array( 'post_type' => 'dwqa-question', 'post__in' => array( 2, 5, 12, 14, 20 ) )
       return $query;
    }

    Plugin Author DesignWall

    (@designwall)

    Hi Prafulla Kumar Sahu,

    Thanks buddy. We do really appreciate your help.

    If there is any more issue with the DW Question & Answer, please do not hesitate to get back to us. It encourages us a lot.

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    I have already posted one or two question, it will great if you will guide me there.

    Plugin Author DesignWall

    (@designwall)

    Hi Prafulla Kumar Sahu,

    Thank you for getting in touch with us. Please try this code below here

    add_filter( 'dwqa_prepare_archive_posts', 'dwqa_refilter_question' );
    function dwqa_refilter_question( $args ) {
     if ( isset( $_GET['filter'] ) && $_GET['filter'] == 'my-answer' ) {
      $user_id = get_current_user_id();
    
      $answer_args = array(
       'post_type' => 'dwqa-answer',
       'posts_per_page' => 5,
       'no_found_rows' => true,
       'update_post_term_cache' => false,
       'update_post_meta_cache' => false,
       'orderby' => 'date',
       'order' => 'DESC',
       'fields' => 'ids',
       'meta_key' => '_question',
       'author' => get_current_user_id()
      );
    
      add_filter( 'posts_where', 'dwqa_answer_post_where' );
      add_filter( 'posts_clauses', 'dwqa_answer_posts_clauses' );
      add_filter( 'posts_distinct', 'dwqa_answer_post_distinct' );
      $questions = new WP_Query( $answer_args );
      remove_filter( 'posts_where', 'dwqa_answer_post_where' );
      remove_filter( 'posts_clauses', 'dwqa_answer_posts_clauses' );
      remove_filter( 'posts_distinct', 'dwqa_answer_post_distinct' );
    
      if ( $questions->have_posts() ) {
       $args['post__in'] = $questions->posts;
      }
     }
    
     return $args;
    }
    
    function dwqa_answer_post_join( $join ) {
     global $wpdb;
     if ( isset( $_GET['filter'] ) && $_GET['filter'] == 'my-answer' ) {
      $join .= 'JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ';
     }
    }
    
    function dwqa_answer_post_where( $where ) {
     global $wpdb;
     if ( isset( $_GET['filter'] ) && $_GET['filter'] == 'my-answer' ) {
      $user_id = get_current_user_id();
      $where .= " AND {$wpdb->postmeta}.meta_key = '_question' ";
     }
    
     return $where;
    }
    
    function dwqa_answer_posts_clauses( $clauses ) {
     global $wpdb;
     $clauses['fields'] = $wpdb->postmeta . '.meta_value';
    
     return $clauses;
    }
    
    function dwqa_answer_post_distinct( $distinct ) {
     return "DISTINCT";
    }
    
    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    thank you so much for your reply, already done it. something like

    add_filter( 'dwqa_prepare_archive_posts', ' my_answered_by_user_function' );
      function my_answered_by_user_function( $query ){
        global $wp_query;
        if ( isset( $_GET['answers_of'] )  ){
          $answer_of = !empty( $_GET['answers_of'] ) ? $_GET['answers_of'] : 'all';
          unset( $args );
          $args = array( 'user' => $answer_of, 'posts_per_page' => -1 );
          $questions_answered = My_Class::my_dwqa_refilter_question( $args );
          $question_ids = array_unique( $questions_answered['post__in'] );
          $query = array( 'post_type' => 'dwqa-question', 'post__in' => $question_ids );
        }
        return $query;
      }

    but thinking to use your .

    Plugin Author DesignWall

    (@designwall)

    Hi Prafulla Kumar Sahu,

    Great to hear that.

    If there is any more issue with the DW Question & Answer, please do not hesitate to get back to us. It encourages us a lot.

    Thread Starter Prafulla Kumar Sahu

    (@prafulla)

    good luck to you ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to extend filter ? in question archive page url’ is closed to new replies.