0
votes

I am trying to get the posts order by a meta_value that i put in a sortable list of posts, i have an extra meta_key and meta_value to give extra info to the query, but i can't make the WP_Query return the post order, do you have any idea that whats is worng?

This is my WP_QUery code:

$args = array(
    'meta_query' => array(
        array(
            'key' => 'portada',                                                  
            'value' => 'on'
        ), array(
            'key' => 'pos',
            'type' => 'numeric'
        )
    ),
'meta_key' => 'pos',
'orderby' => 'meta_value_num');
$loop = new WP_Query($args);
2

2 Answers

1
votes

i use the follow code to solve my problem:

$args = array(
   'meta_query' => array(
       array(
          'meta_key' =>'destacados',
          'meta_value' => 'on'
       )
    ),
    'orderby' => 'meta_value_num',
    'category__in' => $category->cat_ID,
    'meta_key' => 'pos'
);
$loop = new WP_Query($args);

Thank you all :)

1
votes

Note that

 'meta_query' => array(
       array(
          'key' =>'destacados',
          'value' => 'on'
       )
    )

instead of

'meta_query' => array(
       array(
          'meta_key' =>'destacados',
          'meta_value' => 'on'
       )
    )