How to support multiple search terms query within one process?

Fixed:
Search and result the all keys;

    <?php
        $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('s' => get_query_var('s')));

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

Note: 'post_type'=>'nothing' just need array merge!

Leave a Comment