WordPress – Get page/post order number if is set

Does anybody knows how to get the ORDER number inserted in page attributes? I need just the number and if is not set, to give me an specific number (1, or whatever I want) for all pages who don’t have order page number set.

Thank you!

Related posts

Leave a Reply

2 comments

  1. I’m not sure of what you want…

    If you want to retrieve the menu_order from a post/page you can use something like

    <?php
    $id=1;
    $default = 42;
    get_post($id); //you can use any kind of query or use it in the loop
    global $post;
    if(empty($post->menu_order)) //if not set give the value you want
      $post->menu_order = $default; //note that it won't update the value in the database
    echo $post->menu_order;
    wp_reset_query();
    ?>