WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got this theme where you can add posts of type "portfolio", and I want to be able to reorder them up. I've added a custom meta field called "position" and I've set already those values. All good.

My question is: How can I modify the query to join the wp_postmeta table and order them by the "postion" value?

This is the current query:

$loop = new WP_Query( array(
    'post_type' => 'portfolio',
    'posts_per_page' => $homepagenumber
) );

I really appreciate any hint on this. Thanks a lot.

share|improve this question
up vote 1 down vote accepted

Check WP_Query Order by Parameters

 $args = array(
   'post_type' => 'my_custom_post_type',
   'meta_key' => 'age',
   'orderby' => 'meta_value_num',
   'order' => 'ASC',
   'meta_query' => array(
           'key' => 'age',
           'value' => array(3, 4),
           'compare' => 'IN',
 $query = new WP_Query($args);
share|improve this answer
Thanks a lot! PS.-I tried voting your answer up but I couldn't :( (need some reputations points) – Teknotica Feb 7 '13 at 11:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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