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 have a custom loop (used in a shortcode) that lists items from custom post type.

Everything works fine but "order" for posts doesn't work, no matter what I type as order attribute on post page - items are always displayed the same way (the most recent first and the oldest last).

Why doesn't "order" work in my case?

The loop looks like:

  $loop = new WP_Query( array( 
        'post_type' => 'images',   
        'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
        'posts_per_page' => $per_page,
         ) );

while ( $loop->have_posts() ) : $loop->the_post();
(my code)
php endwhile; 
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Add orderby clause to your query! Here is the complete list of order parameters

 $loop = new WP_Query( array( 
        'post_type' => 'images',   
        'orderby' => 'menu_order',
        'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
        'posts_per_page' => $per_page,
         ) );

This query order by the menu order that you have specified in your pages

share|improve this answer
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.