0

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; 
1

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

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.