建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

WordPress 过滤自定义字段不为空的帖子列表

GG网络技术分享 2025-03-18 16:07 6


有时我们需要在列表中显示一个自定义字段不为空的文章。 例如,使用woocommerce插件时,只显示在售的商品,所以代码如下:

$args = array(

'post_type' => 'product',

'meta_query' => array(

array(

'key' => '_sale_price', //自定义字段

'value'=> '',

'compare' => '!='

)

)

);

//另一种形式

array(

'prdctfltr' => 'active',

'post_type' => 'product',

'post_status' => 'publish',

'posts_per_page' => $prdctfltr_global['posts_per_page'],

'meta_query' => array(

array(

'key' => '_visibility',

'value' => array('catalog', 'visible'),

'compare' => 'IN'

)

)

);

标签: WordPress op

提交需求或反馈

Demand feedback