我有下面的代码的结果:的WordPress:多个搜索字词或连接来自多个WP_Queries
$args = array(
's' => 'Apple',
'cat' => 80,
'posts_per_page' => -1,
'orderby' => date,
'order' => desc,
);
$query = new WP_Query($args);
echo $query->found_posts.'<br /><br />';
if ($query->have_posts()) {
while ($query->have_posts()) { $query->the_post();
echo the_time("Y.m.d"); echo ': '; echo the_title(); echo '<br />';
}
}
它搜索80类别包含单词苹果任何职位,然后成功地输出列表这样的帖子像
2
2016.10.10: Apple pie
2016.10.01: Apple juice
如果我也想显示包含单词香蕉的所有帖子,然后我重复刚才的代码's' => 'Apple'
代之以's' => 'Banana'
并获得类似
1
2016.10.05: Banana fresh
很容易,直到我使用像
3
2016.10.10: Apple pie
2016.10.05: Banana fresh
2016.10.01: Apple juice
这里的单一列表我需要你们的帮助,因为我不知道如何实现这一希望输出相关的搜索结果。
到目前为止,我已经试过
$args = array(
's' => array('Apple','Banana'),
'cat' => 80,
'posts_per_page' => -1,
'orderby' => date,
'order' => desc,
);
和
$args = array(
array('s' => 'Apple',),
array('s' => 'Banana',),
'cat' => 80,
'posts_per_page' => -1,
'orderby' => date,
'order' => desc,
);
两个返回所有职位从给定的类别,即使只有一个子数组中的元素,因此它似乎's'
couldn”放在一个子数组中或包含数组作为参数。或者我错了某处,但我无法捕捉到哪里。
意外删除我的评论,而不是编辑。 )无论如何,我只是想补充一点,你提供的功能已经促使我去解决如何仅通过发布内容来限制搜索。非常感谢! )) – YKKY