I'm using the postMash plugin to allow a client to be able to easily reorder posts without having to change the timestamp on each one, and it works fine. However, I'm using a custom loop to call the latest posts in a category onto the home page like so:

$events = get_posts( array ( 'category' => 6, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
if ( $events ) {
    echo '<ul>';
    foreach ( $events as $event )  {
        $eventDate = get_post_meta($event->ID, 'event-date', true );
        $eventTime = get_post_meta($event->ID, 'event-time', true);
        echo "<li>".$eventDate;
        if ($eventDate && $eventTime) {
            echo " - ";
        echo $eventTime."<br>";
        echo "<a href='".get_permalink($event->ID)."'>".get_the_title($event->ID)."</a></li><br>";
    if (++$i == 3) break;
echo '</ul>';


The plugin successfully reorders the posts on the category page, but not within this custom loop..

Here's the plugin url: http://wordpress.org/extend/plugins/postmash/


That plugin is 3 years old. I'm not sure if it uses the menu_order column to set the order but if it does you can filter pre_get_posts or your custom query with:

'orderby' => 'menu_order',
'order'   => 'ASC'

This would all have to be done before the $post object is added to the $events array so it would help answer if you added the code that comes before: if ( $events )

Also if you do a var_dump( $event ) somewhere in your foreach loop we can figure out how the posts are being ordered.


After your comments and looking at the var_dump here is whats going on:

Your getting 5 posts in proper menu order then your break statement causes the foreach loop to start back at 0 then it posts the same 5 posts again. It does this 3 times giving you

1-2-3-4-5 break 1-2-3-4-5 break 1-2-3-4-5 break

See the formated $post array dump: http://pastebin.com/hHPxbzda

If you only want to show the first 3 just add this to your get_posts array:
'posts_per_page' => 3

  • I added the code before - already called orderby and order.. what values from var_dump would you like me to paste here? May 3 '12 at 9:18
  • and do you know if there are any newer plugins that might achieve the same effect? May 3 '12 at 9:19
  • var_dump will give you the menu_order assigned to each each post. All new posts have a default menu_order of 0 which would make them come first unless you create a save_post hook that changes it to something else.
    – Chris_O
    May 3 '12 at 9:53
  • I don't think there is a plugin that does this well but in this question all the code is laid out to make it work.
    – Chris_O
    May 3 '12 at 9:57
  • it's dumping 3 menu_order values per post.. take a look at antonleroux.co.za May 3 '12 at 10:04

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.