orderby and order not working for numeric meta_query

I have a set of default arguments that I pass values in. All of them work when it comes to order and orderby except for member_count which in the database is saved as a string but needs to behave like a number. For this reason I have the type set as numeric and I suspect that the sql casting is working when you do the comparing but not working when you are doing the ordering? Just a guess.

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"
    )
  )
)

);

some of the values i put for orderby have been member_count and meta_value_num member_count and of course DESC and ASC for order

Read more here: orderby and order not working for numeric meta_query

Leave a Reply

Your email address will not be published. Required fields are marked *