Get current menu_order

All we need is an easy explanation of the problem, so here it is.

WordPress implements a simple order functionality by default.

What’s the common method, to retrieve the menu_order for the current post or page?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

If you have the post with an $id:

$thispost = get_post($id);
$menu_order = $thispost->menu_order;

WordPress itself does not provide a function to get the menu_order, so you have to query the post-Object. If you are outside the loop, you can use the above function, however inside the loop you could also achieve this by:

global $post;
$menu_order = $post->menu_order;

The Menuorder is mainly used for Database Queries, as the Name says, do determine the Order of the output (if the menuorder is selected to be the order criteria).

Method 2

You can try following code:

 get_post_field( 'menu_order', $post_id);

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply