0

I have the following query in my query_posts and want to add order by to this. Order by will be on another custom field and sorted by desc order.

Here is my existing query.

//show all active posts for this taxonomy
 query_posts( array(
   'post_type' => APP_POST_TYPE,
   'post_status' => 'publish',
   APP_CUSTOM_TAX => $term->slug,
   'ignore_sticky_posts' => 1,
   'orderby' => 'date', //Instead of this, i want to use custom field like 'votes','date'
   'meta_query' => array(
       'relation' => 'OR',
             array(
                'key' => 'offer_type',
                'compare' => 'NOT EXISTS',
              ),
              array(
                'key' => 'offer_type',
                'value' => 'top',
                'compare' => '!=',
              )
      ))
);

Please suggest.

4
  • Maybe this is what you are looking for: wordpress.stackexchange.com/a/15499/68328 Jun 22, 2018 at 3:27
  • If you search this site for "orderby meta" you'll see that there are many answers to this. Jun 22, 2018 at 15:39
  • @RameshPardhi - Yes, but my challenge is i want the custom field in where clause as well as orderby and i am not sure how to put it in both. Jun 22, 2018 at 17:55
  • Thanks @RameshPardhi, i was finally able to do the orderby with this link on one of the columns, but now i have to do orderby on mutlple columns and it is not working. Any suggestions. 'orderby' => 'votes', 'meta_key' => 'votes', I tried this but doesn't work as expected 'orderby' => array('votes','date'), 'meta_key' => 'votes', Jun 23, 2018 at 3:34

1 Answer 1

0

Have a look at the Codex page - you use 'orderby' => 'meta_value'. Specifically, scroll down a bit and read 'orderby' with multiple 'meta_key's

1
  • i looked at that - but my challenge is i want the custom field in where clause as well as orderby and i am not sure how to put it in both Jun 22, 2018 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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