如何检查该类别是否具有产品或空的WordPress?
大家好,我想知道具有某些自定义属性的特定类别是否具有产品,但我不知道如何使用此功能检查它是否具有
$isset_products_in_category = new WP_Query(
array(
'post_type' => 'product',
'posts_per_page' => -1,
'relation'=>'AND',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => '5',
'operator' => 'IN',
),
array(
'taxonomy' => 'pa_color',
'field' => 'term_id',
'operator' => 'IN',
'terms' => '2',
),
),
'ignore_stickie_posts' => true,
'fields' => 'ids',
)
);
hello guys i'm trying to know if a specific category with some custom attributes has a product or not but i don't know how to use this function to check if it has or no
$isset_products_in_category = new WP_Query(
array(
'post_type' => 'product',
'posts_per_page' => -1,
'relation'=>'AND',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => '5',
'operator' => 'IN',
),
array(
'taxonomy' => 'pa_color',
'field' => 'term_id',
'operator' => 'IN',
'terms' => '2',
),
),
'ignore_stickie_posts' => true,
'fields' => 'ids',
)
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
'关系'=> '和'
应该是sax_query
wp_query()
中的数组的一部分(它定义sax_query
中的阵列之间的关系。修订的代码示例:
'relation' => 'AND'
should be part of thetax_query
array inWP_Query()
(it defines the relationship between the arrays in thetax_query
).Revised code example:
您的WP_QUERY代码中有两个关键问题
i)关系不正确的位置
'关系'=> “和”必须放置在“ sax_query”阵列内,而不是顶层。
2)参数键中的错字
'ignore_stickie_posts'是一个错字;应该是“ image_sticky_posts”。
“关系”必须在tax_query下移动。
校正的代码下面
,然后检查该类别是否具有以下产品或空的产品,
不要忘记
There are two key issues in your WP_Query code
i) Incorrect Placement of relation
The 'relation' => 'AND' must be placed inside the 'tax_query' array, not at the top level.
2) Typos in Argument Keys
'ignore_stickie_posts' is a typo; it should be 'ignore_sticky_posts'.
'relation' must be moved under tax_query.
Corrected Codes below
And then check if the category has products or empty like below
Don't forget to