WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. shortster
    Member
    Posted 1 year 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'];
    relevanssi_do_query($query);

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

    if (is_paged()) {

    becomes

    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
    Member
    Posted 1 year 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;
    
    relevanssi_do_query($wp_query);
    
    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>
          endwhile;
    }
  3. Mikko Saari
    Member
    Plugin Author

    Posted 1 year 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

About this Topic