public function prepare_archive_posts()
 {
     global $wp_query, $dwqa_general_settings;
     $posts_per_page = isset($dwqa_general_settings['posts-per-page']) ? $dwqa_general_settings['posts-per-page'] : 5;
     $user = isset($_GET['user']) && !empty($_GET['user']) ? urldecode($_GET['user']) : false;
     $filter = isset($_GET['filter']) && !empty($_GET['filter']) ? $_GET['filter'] : 'all';
     $search_text = isset($_GET['qs']) ? $_GET['qs'] : false;
     $sort = isset($_GET['sort']) ? $_GET['sort'] : '';
     $query = array('post_type' => 'dwqa-question', 'posts_per_page' => $posts_per_page, 'orderby' => 'modified');
     $page_text = dwqa_is_front_page() ? 'page' : 'paged';
     $paged = get_query_var($page_text);
     $query['paged'] = $paged ? $paged : 1;
     // filter by category
     $cat = get_query_var('dwqa-question_category') ? get_query_var('dwqa-question_category') : false;
     if ($cat) {
         $query['tax_query'][] = array('taxonomy' => 'dwqa-question_category', 'terms' => $cat, 'field' => 'slug');
     }
     // filter by tags
     $tag = get_query_var('dwqa-question_tag') ? get_query_var('dwqa-question_tag') : false;
     if ($tag) {
         $query['tax_query'][] = array('taxonomy' => 'dwqa-question_tag', 'terms' => $tag, 'field' => 'slug');
     }
     // filter by user
     if ($user) {
         $user = get_user_by('login', $user);
         $query['author'] = $user->ID;
     }
     switch ($sort) {
         // sort by views count
         case 'views':
             $query['meta_key'] = '_dwqa_views';
             $query['orderby'] = 'meta_value_num';
             break;
             // sort by answers count
         // sort by answers count
         case 'answers':
             $query['meta_key'] = '_dwqa_answers_count';
             $query['orderby'] = 'meta_value_num';
             break;
             // sort by votes count
         // sort by votes count
         case 'votes':
             $query['meta_key'] = '_dwqa_votes';
             $query['orderby'] = 'meta_value_num';
             break;
     }
     // filter by status
     switch ($filter) {
         case 'open':
             $query['meta_query'][] = array('key' => '_dwqa_status', 'value' => array('open', 're-open'), 'compare' => 'IN');
             break;
         case 'resolved':
             $query['meta_query'][] = array('key' => '_dwqa_status', 'value' => array('resolved'), 'compare' => 'IN');
             break;
         case 'closed':
             $query['meta_query'][] = array('key' => '_dwqa_status', 'value' => array('closed'), 'compare' => 'IN');
             break;
         case 'unanswered':
             $query['meta_query'][] = array('key' => '_dwqa_status', 'value' => array('open', 'pending'), 'compare' => 'IN');
             break;
         case 'subscribes':
             if ($user) {
                 $query['meta_query'][] = array('key' => '_dwqa_followers', 'value' => $user->ID, 'compare' => '=');
             }
             break;
         case 'my-questions':
             if (is_user_logged_in()) {
                 $query['author'] = get_current_user_id();
             }
             break;
         case 'my-subscribes':
             if (is_user_logged_in()) {
                 $query['meta_query'][] = array('key' => '_dwqa_followers', 'value' => get_current_user_id(), 'compare' => '=');
             }
             break;
     }
     // search
     if ($search_text) {
         $search = sanitize_text_field($search_text);
         preg_match_all('/#\\S*\\w/i', $search_text, $matches);
         if ($matches && is_array($matches) && count($matches) > 0 && count($matches[0]) > 0) {
             $query['tax_query'][] = array('taxonomy' => 'dwqa-question_tag', 'field' => 'slug', 'terms' => $matches[0], 'operator' => 'IN');
             $search = preg_replace('/#\\S*\\w/i', '', $search);
         }
         $query['s'] = $search;
     }
     $sticky_questions = get_option('dwqa_sticky_questions');
     // exclude sticky question
     if ($sticky_questions && 'all' == $filter && !$sort && !$search_text) {
         $query['post__not_in'] = $sticky_questions;
     }
     if (is_user_logged_in()) {
         $query['post_status'] = array('publish', 'private', 'pending');
     }
     $wp_query->dwqa_questions = new WP_Query($query);
 }
function dwqa_question_paginate_link()
{
    global $wp_query, $dwqa_general_settings;
    $archive_question_url = get_permalink($dwqa_general_settings['pages']['archive-question']);
    $page_text = dwqa_is_front_page() ? 'page' : 'paged';
    $page = get_query_var($page_text) ? get_query_var($page_text) : 1;
    $args = array('base' => add_query_arg($page_text, '%#%', $archive_question_url), 'format' => '', 'current' => $page, 'total' => $wp_query->dwqa_questions->max_num_pages);
    $paginate = paginate_links($args);
    $paginate = str_replace('page-number', 'dwqa-page-number', $paginate);
    $paginate = str_replace('current', 'dwqa-current', $paginate);
    $paginate = str_replace('next', 'dwqa-next', $paginate);
    $paginate = str_replace('prev ', 'dwqa-prev ', $paginate);
    $paginate = str_replace('dots', 'dwqa-dots', $paginate);
    if ($wp_query->dwqa_questions->max_num_pages > 1) {
        echo '<div class="dwqa-pagination">';
        echo $paginate;
        echo '</div>';
    }
}