0

I have the following args array

{  
   "ordreby":"meta_value_num",
   "meta_key":"_price",
   "posts_per_page":10,
   "offset":0,
   "post_type":"product",
   "post_status":"publish",
   "order":"asc",
   "suppress_filters":false,

}

when i do

  $myposts = get_posts($args);

the order by _price (or other meta keys) is not working.

any idea?

2 Answers 2

1

meta_query should be an array of arrays like:

...
'meta_query' => [
    [
        'key' => '...',
        'value' => '...',
    ],
],
...
1
  • is an array of arrays. The problem is in order by _price Commented Aug 30, 2017 at 15:33
0

Change

"ordreby":"meta_value_num"

for

"orderby":"meta_value_num"

a dyslexic error xD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.