admin管理员组文章数量:1390803
I began slightly baffled and have slowly degraded to slightly going insane as I am building this wp_query.
Admittedly it is a very complex query and there is a lot of additional code that has brought me up to this point so here is the code that is key to helping me resolve to an answer, the wp_query:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => $display_count,
'page' => $paged,
'offset' => $offsetcalc,
's' => $search_term,
'tax_query' => array(
'relation' => $search_relation,
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array($search_tags),
'operator' => $search_relation
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array($search_categories),
'operator' => $search_relation
)
)
);
$the_query = new WP_Query( $args );
Variables are equal to:
$display_count = 9.
$paged = page number.
$offsetcalc = number of products to offset based on calculation done using display count and page.
$search_term = search term entered by user.
$search_relation = user selected string value 'AND' / 'OR'.
$search_tags = tags selected by user.
$search_categories = categories selected by user.
As you can see I am gathering values decided by a user and generating different results based on their inputs.
One of the options I am trying to offer them is the ability to 'show results if the result applies to one of the many options they select' or 'only show results that apply to all the options they select'.
This always works if the user populates the search term field 's'.
This always works if they have the relation set to 'AND'.
However, when the relation is set to 'OR' while also leaving the search term 's' blank, it returns every single result possible.
Please can someone help me successfully implement this 'AND' / 'OR' relation into my wp_query when the search term 's' is left blank?
Massive thanks to contributors, Jason.
本文标签:
版权声明:本文标题:WP_Query | Tax_Query Relation | Unable to use 'OR' as it then allows all products, help me finish my query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744734365a2622234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论