I am trying to implement multi keyword searches on wordpress. Results are loaded via AJAX onto the page, this is the function that runs to get the results (copied and amended from another answer).

I can’t seem to make this work, but I also cant work out why its not working. It just brings up all results as true.

$the_keys = $_POST['query'];

    $the_keys = preg_split('/s+/', str_replace('-',' ',get_query_var('s')),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

    $total_keys = count($the_keys);

    $the_query = new WP_Query(array('post_type' => 'nothing'));


        for($i = 0; $i<=$total_keys; $i++) {

            $the_query_mask = new WP_Query(array(
                's' => $the_keys[$i]));

            $the_query->post_count = count( $the_query->posts );
            $the_query->posts = array_merge( $the_query->posts, $the_query_mask->posts );

    } else {

        $the_query= new WP_Query(array(
            'post_type' => 'days',
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'order' => 'DESC',
            's' => get_query_var('s')));


    if ($the_query->have_posts()) : ?>

Read more here: Multi Keyword Search on WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: