对于multiple 搜索词;?s=hello+world
Wordpress工作查找"hello world" 喜欢the_title
, the_content
帖子!
如果我们的帖子标题Hello Anna
wordpress没有得到一个结果我要使用所有键:
"hello world" , "hello" , "world"
Maybearray(\'hello world\',\'hello\',\'world\');
但它超过了我的经验。!它是否在单个循环中可以分割查询并发送多个查询?有人能在这方面提供帮助吗?e.g. ?s=
, $_GET
想要的东西一定像是调用多个查询的更多结果!
最合适的回答,由SO网友:lllllllllllll 整理而成
固定:搜索和结果的所有关键点;
<?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()) : ?>
注:
\'post_type\'=>\'nothing\'
只需要阵列合并!
SO网友:lllllllllllll
也许像我这样的人fuzzy logic results
我这样解决:"search.php
"
<?php
$the_keys = preg_split(\'/\\s+/\', get_query_var(\'s\'),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$total_keys = count($the_keys); // Count the search term
$the_query = new WP_Query(array(\'s\' => get_query_var(\'s\')));
// IF have multiple term and havent a result
if($total_keys > 1 && $the_query->post_count < 1){
// Loop for total term count, if found post break it! <3
for($i = 0; $i < $total_keys; $i++) {
//Set the new array term value
$the_query = new WP_Query(array(\'s\' => $the_keys[$i]));
//if found post break it! <3
if($the_query->post_count>0) break;
}
}
// List of my Level 2 filter posts :)
if ($the_query->have_posts()) : ?>
......
<?php
endwhile;
endif;
?>
e.g. 职务:(Hello baby )
正常:
?s=hello+baby
=> find true?s=hello
=> find true?s=baby
=> find true?s=hello+whats+up
=> find false?s=hey+baby
=> find false
搜索、立即工作并查找
e.g. ?s=hello+whats+up
=>
find true