wordpress – proper foreach in array syntax

I’m still very novice at PHP so any help is greatly appreciated. I’m using a custom menu to display 4 posts, and for each post I’d like the post thumbnail. My code is below, which gives me an invalid argument supplied error.

    <div id="stampnav">
    <?php $pages = wp_nav_menu( array( 'container_class' => 'menu-header','theme_location' => 'stamp-menu' ) ); 
    foreach($pages as $pagg) {

    echo get_the_post_thumbnail($pagg->ID, 'thumbnail'); }
    ?>
    </div>

Related posts

Leave a Reply

1 comment

  1. You need to call global $post and make a query to get the post thumbnail the menu will not return the meta associated with the page, it only queries the built in “menu” custom post type.

    Your other option is to create a custom Walker Class for your nav menu.