【发布时间】:2021-03-05 07:21:04
【问题描述】:
我试图在 woocomerce 管理面板中获取最昂贵产品的价格(或 ID)。使用下面的代码,我不断获得无限循环,尽管我不确定这是否是正确的方法。尝试了许多不同部分的函数形式堆栈,但它没有帮助我。
unction test() {
$args = array(
'category' => array( 'blackcat' ),
'orderby' => 'name',
);
$products = wc_get_products( $args );
}
add_action( 'pre_get_posts', 'test' );
$query = array(
'limit' => 1,
'post_type'=> 'product',
'orderby' => 'price',
'order' => 'ASC',
);
$the_query= new WP_Query($query);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
}
}
}
add_action( 'parse_query', 'apply_my_custom_product_filters' );
两者都返回 /wp-includes/class-wp-query.php 中耗尽的.....字节的允许内存大小
【问题讨论】:
标签: php wordpress woocommerce