For multiple search terms; ?s=hello+world
WordPress work find “hello world” like the_title
, the_content
posts!
- And, if our post title
Hello Anna
wordpress does not get one results!
I want to use all keys:
“hello world” , “hello” , “world”
Maybe
array('hello world','hello','world');
but it exceeds my exp.!
Is it in a single loop may be able to divide the query and send multiple queries? Is there someone who can help on the subject? e.g. ?s=
, $_GET
Wanted something must have been like to call more results for multiple queries!
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!