【发布时间】:2021-10-24 18:53:39
【问题描述】:
我正在尝试创建此自定义产品查询,以便仅在 /shop 页面上显示带有以下 tax_query 的产品。但它不起作用。
我也尝试了woocommerce_product_query 钩子。
感谢任何建议!
add_action( 'pre_get_posts', 'show_active_lotteries_only' );
function show_active_lotteries_only( $q ){
$q->set( 'tax_query', array (
array(
'fields' => 'ids',
'post_type'=> 'product',
'show_past_lottery' => FALSE,
'tax_query' => array(array('taxonomy' => 'product_type' , 'field' => 'slug', 'terms' => 'lottery')),
)
));
}
The query is taken from the lottery plugin documentation (the product being used in the store):
// Return active lottery products.
$args = array(
'fields' => 'ids',
'post_type'=> 'product',
'show_past_lottery' => FALSE,
'tax_query' => array(array('taxonomy' => 'product_type' , 'field' => 'slug', 'terms' => 'lottery')),
);
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce woocommerce-theming