wordpress - Loop 产品不包括在售仅显示 4 件商品
问题描述
我正在根据我找到的代码示例(仅检索到的原始产品)检索不包括在售产品的最新产品。这就是我所做的:
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'orderby' =>'id',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '=',
'type' => 'numeric'
),
array( // Variable products type
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '=',
'type' => 'numeric'
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
实际上它只检索 4 种产品(我需要 8 种),这些不是最新的,但它正确地排除了特价产品。
任何想法?谢谢你。
解决方案
(已编辑)这将处理简单的产品。我试图找到如何处理变化,但找不到在创建销售价格时设置的任何元键。无论如何,“比较”不应该是“或”,而应该是“与”,因为您希望找到没有任何这些元值的产品。
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'orderby' =>'id',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => '_sale_price',
'compare' => 'NOT EXISTS',
),
)
);
推荐阅读
- flutter - Flutter ListTile 飞溅/波纹效果与边框不匹配
- firebase - 无法设置 Cloud Firebase 每日支出限额
- objective-c - 架构 arm64 的 J2ObjC 未定义符号
- floris - 访问每个涡轮机的风速
- jira - 在 JIRA SOFTWARE TOOL 中为用户提供授权(Oauth 2.0)的方式有哪些?
- c# - 拒绝访问无法连接:无效设置
- sql - 在 2 个不同的行中显示 2 列 - SQL
- r - 绘图中缺少数据,但使用 R 中的 ggplot 数据存在于数据集中
- siddhi - 编写 siddhi 自定义函数/流扩展,既不获取函数扩展,也不获取聚合属性扩展
- java - 类对象的泛型