0

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.

1 Answer 1

0

So I was using wordpress search and clearly I was passing parameters like this :

http://example.com/?s=test&passage=200&kind=none

But the problem is I have a taxonomy called passage, exactly like the parameter I was sending to the wordpress search page. My guess is this is a little confusing for wordpress and changing my parameter name to something else, solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.