我想在 wordpress 中按价格订购帖子,我尝试了很多并且还关注文档,一切看起来都不错,但仍然无法正常工作..
这是代码....
global $wp_query;
$query_vars = $wp_query->query_vars;
$post_per_page = 12;
global $term;
$term = (strip_tags($_GET['term']));
if (!empty($_GET['term'])) {
add_filter('posts_where', 'taskerdev_posts_where');
}
$meta_query = array();
$closed = array(
'key' => 'closed',
'value' => "0",
'compare' => '='
);
$meta_query[] = $closed;
if (!empty($_GET['tasker_cat_cat']))
$tasker_cat = array(
'taxonomy' => 'tasker_cat',
'field' => 'slug',
'terms' => $_GET['tasker_cat_cat']);
$meta_query[] = $tasker_cat;
$price = array(
'meta_key' => 'price',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$meta_query[] = $price;
$args = array('post_type' => 'shoping', 'posts_per_page' => 10,
'paged' => $query_vars['paged'], 'meta_query' => $meta_query);
这段代码看起来不错,但我无法通过 post_meta 中的价格获得发布订单。我可以看到这段代码对每个位置的结果进行排序,即使在 wp_query 的文档中也是如此。
$price = array(
'meta_key' => 'price',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$meta_query[] = $price;