wordpress menu_order not working

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

Read More
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 ?

Related posts

Leave a Reply

4 comments

  1. 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:

        $children = get_pages('child_of='. $topID); 
    
        // 'sort_column=menu_order' <-- only sorts by post order in writing mode (page > edit) not the menu order set in view > menus
        // wp_nav_menu has what we need, let's sort it the same way.
        $options = array(
            'container' =>  '',
            'echo'      =>  false,
    
        );                      
        $nav = wp_nav_menu($options);       
        $nav = strip_tags($nav);        
        $nav = str_replace("r", '', $nav);
        $nav = explode("n", $nav);
        //print_r($nav);
        $newChildren = array();
        foreach ($nav as $item) {
            $item = trim($item);
            $run = true;
            for ($c = 0; $c < count($children) && run; $c++) {              
                $child = $children[$c];
                if (strcmp($child->post_title, $item) == 0 && !in_array($child, $newChildren)) {
                    $newChildren[] = $child;                    
                    $run = false;
                }
            }
    
            // Adding the children the nav_menu is lacking, not sure why not all sub-children 
            //  are added to the first child here..(works but don't know why :/)
            if ($run == true) {
                for ($c = 0; $c < count($children) && run; $c++) {              
                    $child = $children[$c];     
                    if (!in_array($child, $newChildren)) {
                        $newChildren[] = $child;
                    }
                }           
            }
        }
        $children = $newChildren;