我有下面的代碼的結果:的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