I'm trying to find a way to pass the Relevanssi found number of posts into Timber pagination. Currently, it is using the default query's found number of posts instead of Relevanssi's.
My search.php template looks like this:
$searchQuery = get_search_query();
$args = array(
'post_type' => array('post', 'page'),
'posts_per_page' => 10,
's' => $searchQuery,
'post_status' => 'publish',
'relevanssi' => true,
'paged' => $paged
);
$query = new WP_Query();
$query->parse_query($args);
$relposts = relevanssi_do_query($query);
$postsLength = sizeof($relposts);
$context['found_count'] = $query->found_posts;
$context['found_posts'] = $relposts;
$context['pagination'] = Timber::get_pagination();
In case it matters, I then loop through the found_posts variable in the .twig template to populate the search results. Everything works as expected except pagination, which has more pages than necessary (Relevanssi found posts are fewer than the default search's found posts).
Any help is much appreciated, thanks!
I managed to get a similar query working as follows:
$args = array(
'post_type' => array('post', 'page'),
'posts_per_page' => 10,
's' => $searchQuery,
'post_status' => 'publish',
'relevanssi' => true,
'paged' => $paged
);
$found_posts = new Timber\PostQuery($args);
$context['found_posts'] = $found_posts;
$context['pagination'] = $found_posts->pagination();