0 Replies - 813 Views - Last Post: 07 August 2018 - 10:06 AM

#1 ratonhnaketon   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 07-January 16

404 Error on custom query pagination

Posted 07 August 2018 - 10:06 AM

I have to kinds of search forms in my sidebar. Both of this forms are handled in search.php page by an if/else statement and write a custom query for both of them. I also replace the default wordpress query with mine so the the_posts_pagination works correctly. for my first search query, it's working perfect and showing the right numbers, but in my second query, it shows the right page numbers but when i click on the numbers, 404 page! Here is a piece of my code :

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
if(fist form is filled) {


    $adSearchQuery = new WP_Query(array(
        'post_type' => 'post',
        'category__in' => array(1,3,4),
        'posts_per_page' => 3,
        'paged' => $paged
    ));

    $temp_query = $wp_query;
    $wp_query   = NULL;
    $wp_query   = $adSearchQuery;

    // Show posts 

    the_posts_pagination(); 

    $wp_query = NULL;
    $wp_query = $temp_query;

    wp_reset_postdata();
}
else {
    $tax_query = array(
        array(
            'taxonomy' => 'health',
            'field' => 'term_id',
            'terms' => "126"
        )
    );
    $aposts = new WP_Query(array(
        'type' => 'post',
        'category_name' => "test",
        'tax_query' => $tax_query,
        'posts_per_page' => 3,
        'paged' => $paged
    ));

    $temp_query = $wp_query;
    $wp_query   = NULL;
    $wp_query   = $aposts;

    // Show posts 

    the_posts_pagination();

    $wp_query   = NULL;
    $wp_query   = $temp_query;

    wp_reset_postdata()
}

But I don't know why the second pagination is not working though it has the right number of total posts and page numbers.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1