1

In my search page, My query returns 11 pages with this search: ?q=2&s=chem

But when I try to access another page other than the first, like ?q=2&s=chem&paged=2 for example, WordPress shows error not found.

Note: If I leave empty s variable in URL, I have no problem.

This is my WP_Query :

$args = array(

'number' => $number,
'offset' => $paged ? ($paged - 1) * $number : 0,
's' => $_GET['s'],
'meta_query' => array(
    'relation' => 'OR',
    [
        'key'          => 'comp_name',
        'value'        => $_GET['s'],
        'compare'      => 'LIKE'
    ]
),);

Someone knows how to fix this problem?

11
  • 1
    update your permanent links under settings Aug 1, 2017 at 14:26
  • thank you, i check this but not working. Aug 1, 2017 at 14:28
  • 1
    you checked and changed ? or just checked ? :) Aug 1, 2017 at 14:29
  • 1
    change to "Custom Structure" Aug 1, 2017 at 14:30
  • 2
    404 is based on the main query, the query you run in the template is irrelevant.
    – Milo
    Aug 1, 2017 at 15:14

1 Answer 1

1

by default, wordpress has it's own main query in search page, in your case you didn't changed the main query, and just create a custom query

paged is a reserved query variable which is used first by your main query, when your main query dosent have same results, you face a 404 error you have 3 choices:

1. change paged variable

you can rename your page variable from paged to page or something else which is not used by wordpress by default

2. override 404 page

function override_404() 
{
    if ( is_search() && isset($_GET['s'])) {
        global $wp_query;
        $wp_query->is_404 = false;
    }
}
add_action('init', 'override_404');

3. override main query ( best )

function change_search_query() {
    if ( is_search() && isset($_GET['s'])) {
        $args = array();
        query_posts( $args );
    }
}
add_action('init', 'change_search_query');
1
  • I tried the same as shown above but not working still going on 404 page as soon as we click on next pagination link. For first time its ok. Dec 12, 2018 at 12:36

Your Answer

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

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