orderby和order不适用于数字meta_query

时间:2017-04-26 03:04:26

标签: php sql wordpress

我有一组默认参数,我传入了值。除了member_count之外,所有这些参数都在订单和订单中有效,而public $default_args = array( 'post_type' => 'clans', 'post_status' => 'publish', 'posts_per_page' => -1, "s" => '', "post__in" => "", "orderby" => '', "order" => '', "date_query" => array( "before" => '', "after" => '', "inclusive" => true ), "meta_query" => array( "relation" => "AND", "average_skill_level" => array( "key" => "average_skill_level", "compare" => "EXISTS", ), "activity_level" => array( "key" => "activity_level", "compare" => "EXISTS", ), "language" => array( "key" => "language", "compare" => "EXISTS", ), "applications" => array( "key" => "applications", "compare" => "EXISTS", ), "member_count" => array( array( "key" => "member_count", "compare" => ">=", "type" => "NUMERIC" ), array( "key" => "member_count", "compare" => "<=", "type" => "NUMERIC" ) ) ) 在数据库中保存为字符串但需要表现得像一个数字。出于这个原因,我将类型设置为数字,我怀疑在进行比较时sql转换是否正常工作但在进行排序时不能正常工作?只是一个猜测。

member_count

);

我为orderby提供的一些值为meta_value_num member_countDESC,当然还有ASC和{{1}}的订单

1 个答案:

答案 0 :(得分:0)

"member_count" => array(
    "member_min" => array(
      "key" => "member_count",
      "compare" => ">=",
      "type" => "NUMERIC"
    ),
    "member_max" => array(
      "key" => "member_count",
      "compare" => "<=",
      "type" => "NUMERIC"
    )
  )

我将这两个数组命名为member_count,最后按这些键排序。