Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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(
       array(
           'key' => 'age',
           'value' => array(3, 4),
           'compare' => 'IN',
       )
   )
 );
 $query = new WP_Query($args);
share|improve this answer
1  
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
add comment

Your Answer

 
discard

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.