Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Displays posts based on what has been added to a menu location
<?php
$menu = 'featured-content'; // Replace with your menu name
if ( has_nav_menu( $menu ) ) :
// Get post ids of items in the menu
$items = wp_get_nav_menu_items( $menu );
foreach ( $items as $item ) {
$ids[] = get_post_meta( $item->ID, '_menu_item_object_id', true );
}
// var_dump( $ids );
if ( isset( $ids ) ) :
$args = array(
'posts_per_page' => 6, // # of posts to appear
'post_type' => array( 'post', 'page', 'guide' ), // Post types
'post__in' => $ids,
'orderby' => 'post__in'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="article">
<a href="<?php the_permalink(); ?>">
<div class="image">
<?php the_post_thumbnail(); ?>
</div>
<h3><?php the_title(); ?></h3>
</a>
</div>
<?php endwhile;
endif;
wp_reset_query();
endif;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment