The problem is that the order of the home page is not correct anymore. The new items are not in the same order as the menu, even though this is active:

'orderby'   => 'menu_order', 
'order'     => 'asc' 

In the database I can see that every new page, type=project, used to have a menu_order assigned but not anymore? The menu_order for every new page is 0.

How is this possible?


thank you for your help. Projects is a custom post type. In a custom page template I have the following code:

array('projects'), 'orderby' => 'menu_order', 'order' => 'asc', 'post_status' => 'publish' )); if ( have_posts() ) while ( have_posts() ) : the_post(); ?> The template is created by someone else. It has been explained to me by the site owner/editor that he changed the menu ordering and then the page displayed the projects in the same order. But now (since the new theme) this does not work anymore. The only thing I can find in the code is what you see above. I added the page-attributes and now I can manually change the order. But this is still not what the client used to do..

  • "used to be assigned"? You mean you had manually assigned an order and it has disappeared?
    – s_ha_dum
    Dec 17, 2015 at 15:09
  • 'orderby' => 'menu_order', 'order' => 'asc' has nothing to do with assigning menu_order; it's a query modifier for returning posts according to a sort on the column menu_order. Something else in your code must be changing or neglecting to set menu_order on wp_insert_post or wp_update_post...
    – C C
    Dec 17, 2015 at 15:19
  • The default menu_order for any new Post is 0, so unless you either set the order manually for each Post, or have some code in play to hook wp_insert_post_data, the results you describe should be expected.
    – David Gard
    Dec 17, 2015 at 16:24
  • You could implement auto-incrementing.
    – Howdy_McGee
    Dec 17, 2015 at 16:30

1 Answer 1


Why this is happening

The default menu_order is 0, so unless you manually change this any new Page/Post inserted in to your DB will correctly have this menu_order set.

You can set the menu_order for any Page via Quick Edit as below (or indeed the Edit Page screen if you wish) -

Set Menu Order via Quick Edit

By default, Post and Custom Post Type posts don't have the muen_order attribute, meaning that 0 will always be used, but this can be overridden (keep reading to see how).

I see from your question that mention type=project; I'm not sure if you are referring a Custom Post Type, or if type is a Custom Field.

Assuming "project" is a Custom Post Type

You can add the menu_order attribute any Custom Post Type very easily; simply ensure that you include page-attributes in the supports argument when declaring the Custom Post Type -

'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes'),

Assuming "project" is a Custom Field

If you are trying to display posts of the built-in type Post, meaning that project is a Custom Field, then you need to add the menu_order attribute to the Post type -

add_action('admin_init', 'add_post_page_attributes');
function add_post_page_attributes(){

    add_post_type_support( 'post', 'page-attributes' );


Changing the default "menu_order"

If you wish, you can use the following code to override the default menu_order and set it to whatever you desire.

I use this code myself because I have a unique requirement to order 1-100 posts in a non-standard order, followed by the remainder in alphabetical order. I use 100 as a default, but you can change this to whatever you want -

add_filter('wp_insert_post_data', 'set_default_menu_order', '99', 2);
function set_default_menu_order($data, $postarr){

    if($data['post_type'] === 'post') :                                                     // Ensure we're saving a desired Post Type...
        $data['menu_order'] = ($data['menu_order'] == '0') ? '100' : $data['menu_order'];   // ...Check to see if a 'menu_order' has been set; if so, keep it, if not, use the default

    return $data;   // Return the new data

  • Thank you David. If I understand correcty the menu_order is changed after manually chaging the order in WP > Menus. This is what I did and it does not change anything? Dec 18, 2015 at 9:38
  • No, those are navigation menus (see the Function Reference for wp_nav_menu()). You need to edit the menu_order of your Page (see my update).
    – David Gard
    Dec 18, 2015 at 11:09
  • Hi David, thank you for your help. See my other answer. Dec 21, 2015 at 19:13

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.