admin管理员组文章数量:1313756
I've tried searching to no avail, and it may be that I'm not sure what it is I'm actually searching for. I am trying to use the WP_Query to display a list of posts that contain ANY (not ALL) of the keywords.
So, here is my code:
<?php
$queertionary_index_all = new WP_Query(
array(
'post_type' => 'Definitions',
'posts_per_page' => 30,
'order' => 'ASC',
'post__not_in' => array(get_the_ID()),
'orderby' => 'relevance',
'sentence' => false,
's' => 'fairy',
)
);
?>
This, rightly, displays all the posts that contain the term "fairy".
However, I want it to display all the posts that contain EITHER the term "fairy" OR the term "Ursula".
I have tried numerous things, such as 's' => array('fairy','Ursula'), but this either displays ALL the posts, regardless of whether they contain "fairy" or "Ursula" or not, or it displays none at all (I'm assuming because none of the posts contain both terms).
Is there a way to do this?
I'm curious as to whether the solution is in functions.php, because I notice that using the search form for "fairy" does as it's supposed to, but searching for "fairy Ursula" will bring up nothing, because as said, there's no posts that contain BOTH terms.
It'd be great if there was a solution that could universally solve this, so that "fairy Ursula" would work in both search results and WP_Query to bring up posts with EITHER "fairy" or "Ursula" in them, but if not, my priority would be a WP_Query solution.
I'd really prefer not to use a plugin if possible.
Any help you could offer me in this respect would be very gratefully appreciated!
Many thanks.
本文标签: wp queryMultiple Search Terms WPQuery
版权声明:本文标题:wp query - Multiple Search Terms WP_Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741922972a2405115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论