I don’t know what is wrong with menu_order but the posts are not displayed as I want. Here is what I mean
I have 3 posts in my blog. Here is how db looks like
id ..... menu_order
56 ..... 2
59 ..... 5
65 ..... 3
index.php (my custom theme)
I want to display only image so here is the code that I use
<?php while ( have_posts() ) : the_post();
$images = get_children(
array( 'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'DESC',
'numberposts' => 999 )
);
if( $images )
{
$total_images = count( $images );
$image = array_shift( $images );
echo wp_get_attachment_image($image->ID, 'full', 0, array('id' => 'photo'));
}
endwhile; // end of the loop.
?>
The problem is that the posts are displayed in order with id 65,59,56 and not as I expect 59,65, 56
What is wrong with this ?
Use the following code. It will solve your issue
‘sort_column’ => ‘menu_order’
I would use
get_posts()
with the same parameters instead. See here.Seems like this
menu_order
isn’t what you’d think, eg. the order you have chosen on your site custom menu. Instead it’s the order you set every page under writing… This is not what I want either so I made this solution:sort_column=menu_order only sorts pages based on their order in writing not the order you set in view > menus (translated), if you want that you can do like this:
when you populate the menu, add
sort_column=menu_order
: