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'));

    if($total_keys>1){

        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')));
    }

    ob_start();

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

Read more here: Multi Keyword Search on WordPress


Solution:

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: