Php 管理中最昂贵的Woocomece产品的价格
我试图在Woocomece管理面板中获取最昂贵产品的价格(或id)。有了下面的代码,我不断得到无限循环,尽管我不确定这是否是正确的方法。尝试了堆栈中函数的许多不同部分,但对我没有帮助Php 管理中最昂贵的Woocomece产品的价格,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图在Woocomece管理面板中获取最昂贵产品的价格(或id)。有了下面的代码,我不断得到无限循环,尽管我不确定这是否是正确的方法。尝试了堆栈中函数的许多不同部分,但对我没有帮助 unction test() { $args = array( 'category' => array( 'blackcat' ), 'orderby' => 'name', ); $products = wc_get_products( $args ); } add_action
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中耗尽的字节数已经计算出来了。我上错地方了。应该使用“限制\管理\帖子”
add_action('restrict_manage_posts', 'yet', 10);
function yet(){
$args = array(
'post_type' => 'product',
'posts_per_page' => '1',
'orderby' => 'price',
'order' => 'DESC',
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
}