Wordpress - Get page / mail order number, if installed

Does anyone know how to get the ORDER number inserted in the page attributes? I only need a number, and if not set, give me a specific number (1 or everything I want) for all pages that do not have an order page number.

Thank!

+3
source share
2 answers

I'm not sure what you want ...

If you want to get 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();
?>
+6
source

Better to use this method:

        $my_menu_order = get_post_field( 'menu_order', $id, true );

where $ id is the message identifier

0
source

All Articles