I'm having an issue with the order of search results loaded via AJAX, it never matches the order of the same query on the search results page. The AJAX response WP_Query instance uses the following arguments:
$query_args = [
'cat' => '-7',
'orderby' => 'relevance',
'order' => 'DESC',
'post_type' => ['features', 'how-to-guides', 'post', 'page', 'testimonials'],
'posts_per_page' => 8,
'post_status' => 'publish',
's' => (isset($_GET['search_term']) === true) ? filter_input(INPUT_GET, 'search_term', FILTER_SANITIZE_SPECIAL_CHARS) : '',
'meta_query' => [
[
'compare' => 'NOT EXISTS',
'key' => 'thank_you_page',
'value' => 'on',
'type' => 'CHAR'
]
],
'tax_query' => [
[
'field' => 'slug',
'operator' => 'NOT IN',
'taxonomy' => 'resources-categories',
'terms' => ['hidden']
]
]
];
I've tried removing everything from the query apart from the order, orderby and it doesn't matter if the order is set to "DESC", "ASC" or if the orderby is set to "relevance", "title" etc, it has no impact on the order of the AJAX results.
Has anyone else ever encountered this issue before? If you have, did you find a way to make the order match the same query on the search results page?