我有产品发布类型, 我有product_cat是分类法。在product_cat中, 我有红色, 硬, 软笔整体。
所以我必须让产品变红, 变硬或变软
我怎么能得到这个?
对于红色, 硬性和软性两种产品, 我可以使用以下查询
$args = array(
'post_status' =>
'publish', 'posts_per_page' =>
-1, 'tax_query' =>
array(
'relation' =>
'AND', array(
'taxonomy' =>
'product_cat', 'field' =>
'slug', 'terms' =>
'red'
), array(
'taxonomy' =>
'product_cat', 'field' =>
'slug', 'terms' =>
'hard'
), array(
'taxonomy' =>
'product_cat', 'field' =>
'slug', 'terms' =>
'soft'
)
), 'post_type' =>
'product', 'orderby' =>
'title', );
但是我需要的是红色, 必须是红色或红色。即(红色& & (软||硬))
请帮忙 。
#1你可以这样尝试:
'tax_query' =>
array(
'relation' =>
'AND', array(
'taxonomy' =>
'product_cat', 'field'=>
'slug', 'terms'=>
array( 'red' ), ), array(
'relation' =>
'OR', array(
'taxonomy' =>
'product_cat', 'field'=>
'slug', 'terms'=>
array( 'hard' ), ), array(
'taxonomy' =>
'product_cat', 'field'=>
'slug', 'terms'=>
array( 'soft' ), ), ), ),
未经测试, 但应该可以使用!
如果没有, 这里有一些有用的链接:
https://codex.wordpress.org/Class_Reference/WP_Query
【具有和或条件的WordPress分类法查询】
Mixed relationship taxonomy queries in WordPress
推荐阅读
- WordPress Style.css标头错误
- WordPress的分类术语还包含仪表板页面吗()
- 分页存档页面上的WordPress粘帖
- WordPress style.css损坏
- WordPress-在transient中存储URL不是常量
- 所有主题的WordPress静态主页
- #yyds干货盘点#算法给小码农二叉树OJ淬体
- #私藏项目实操分享#Java深层系列「技术盲区」让我们一起去挑战一下如何读取一个较大或者超大的文件数据!
- #yyds干货盘点#算法给小码农归并排序列阵