Posted on

Ajax Load More

Ajax Load More is an infinite scrolling plugin for WordPress. It has a Relevanssi extension, but with the current versions of Ajax Load More (5.5.4.1 as I write this), the extension no longer does anything. The extension relies on a filter hook that does not exist in the plugin.

Instead of the extension, you can make Ajax Load More use Relevanssi by adding this function to your site:

add_filter( 'alm_modify_query_args', function( $args ) {
    $args['relevanssi'] = true;
    return $args;
} );

This function enables Relevanssi in the Ajax Load More queries.

Every time Ajax Load More loads more results, it counts as a new search for Relevanssi logs. If you don’t like that, you can make Relevanssi only log the first Ajax Load More search. If you want that, use these functions instead of the one above:

add_filter( 'alm_modify_query_args', function( $args ) {
    global $rlv_is_offset_query;
    $args['relevanssi'] = true;
    if ( $args['offset'] ) {
        $rlv_is_offset_query = true;
    }
    return $args;
} );

add_filter( 'relevanssi_ok_to_log', function( $ok, $query ) {
    global $rlv_is_offset_query;
    if ( $rlv_is_offset_query ) {
        $ok = false;
    }
    return $ok;
}, 10, 2 );

Now Relevanssi logs each search query only once.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *