1
我使用wp_query
并使用元键对结果进行排序,问题是它排除了我在排序的列中没有输入任何内容的产品。我需要所有的产品,包括没有评分最高的顶级产品。wp_query和元数据排序排除没有条目的产品
else if($field == "rating") {
$myArgs = array(
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'include' => '',
'meta_key' => 'rating',
'post_type' => 'job_listing',
'post_status' => 'publish',
'job_listing_region' => 'London',
'compare' => ''
);
}
更新:原来我wsn't得到我所需要的排序结果,改变了代码以下,但结果仍然是独家的非等级产品。
$myArgs = array(
'orderby' => 'meta_value_num',
'order' => 'DESC',
'post_type' => 'job_listing',
'post_status' => 'publish',
'job_listing_region' => "'" . $city . "'",
'meta_query' => array(
array(
'key' => 'rating',
'compare' => '<'
),
)
);
可能的解决方案是保存默认(空)meta值与所有产品。 –
该评级是用户生成的,但我假设数据库中有空白空间或NULL作为默认值,可能是NULL。 –
在那里可能是空的。如果没有用缺省值填充所有元值,我想不出任何解决方案。 –