Relevanssi - A Better Search
[resolved] Relevanssi used with ajax, little pagination issue (3 posts)

  1. shortster
    Posted 3 years ago #

    I'm using Relevanssi to display search results with ajax. This works fine, however, pagination will not work because is_paged() returns nothing (relevanssi/lib/search.php line 737)

    To make the plugin a little more flexible could you please replace the is_paged() call with a check if the query_vars['paged'] is bigger than 0. It's the same thing except now it's possible to use this variable to show the right page in the pagination using:

    $query->query_vars['s'] = 'search term';
    $query->query_vars['posts_per_page'] = 10;
    $query->query_vars['paged'] = $_POST['paged'];

    The change in relevanssi/lib/search.php lin 737:

    if (is_paged()) {


    if ($query->query_vars['paged'] > 1) {

    Unless you know a better way of course, I really don't want to alter the plugin's code.

  2. shortster
    Posted 3 years ago #

    Fixed it using a different route. Maybe helpful for someone else, here's what I did.

    Inside my function:

    global $wp_query;
    $wp_query = new WP_Query('paged=' . $_POST['paged']);
    $wp_query->query_vars['s'] = $_POST['search'];
    $wp_query->query_vars['posts_per_page'] = $postPerPage;
    if($wp_query->have_posts()) {
          while ($wp_query->have_posts()) : $wp_query->the_post();
                 <a href="<?php the_permalink(); ?>" rel="external"><?php the_title();?></a>
  3. Mikko Saari
    Plugin Author

    Posted 3 years ago #

    Glad to hear you were able to fix it. I did make the change, though, it'll be effective from the next version on.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic