0
$args = [
        's' => $autocompleteTerm,
        'orderby' => 'modified',
        'fields' => 'all',
        'post_status' => array('publish','future'),
    ];

$posts_query = new \WP_Query($args);
return $posts_query->get_posts();

$autocompleteTerm is a string of what I am searching for, for example, if I publish an article with title 'top 10 candies'

when $autocompleteTerm = 'top 10', return is empty.

it works if $autocompleteTerm = 'top' instead

  • You probably need to show how $autocompleteTerm is constructed to answer this. – vancoder Sep 16 '20 at 19:56
  • updated my question – RRRRR Sep 16 '20 at 21:04
  • 1
    I have tested Your code and it is working fine by both values. – Hector Sep 17 '20 at 4:46
  • in that case seems related to my environment, i went ahead commented out all non official filter for 'posts_where' and still getting empty result for 'top 10' – RRRRR Sep 17 '20 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.