【发布时间】:2013-08-05 13:48:53
【问题描述】:
我目前正在遍历所有帖子并显示 post_meta 值,如下所示:
global $wpdb;
$table = $wpdb->prefix . 'postmeta';
$theid = get_the_id();
$getLowestPrice = $wpdb->get_results("SELECT * FROM $table WHERE meta_value = '$theid'");
foreach ( $getLowestPrice as $post ){
get_post_meta( $post->post_id, '_wholesale_price', false );
}
有没有办法对结果进行排序,最低 -> 最高?目前它们是随机显示的,或者按照输入的方式显示。
【问题讨论】:
-
你可以像下面这样使用 wp 查询
$query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value', 'meta_key' => 'price','order' => 'ASC' ) ); -
我试过了,这只是得到一个连续循环?
-
只需将
'meta_key' => '_wholesale_price'放在上面的查询中,而不是'meta_key' => 'price' -
这就是我所做的,但它只是不断循环
-
你能告诉我你的整个页面代码吗?