Get menu_order Value

I usually use a counter to show show items in a list, but I was recently working with numbered Modules, and needed specific values associated with each Page / Post, so instead I found myself using menu_order.

Here you can get the value of the menu_order field to show on a single Page or Post:

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

Source.

Within the loop:

foreach($modules as $post) : setup_postdata($post);  ?>
	<div class="module">
		<span><?php echo $post->menu_order; ?></span>
		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
	</div>
<?php endforeach; wp_reset_postdata(); ?>

 

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.