I'm changing a menu from a loop with query_posts to a "custom menu" using wp_get_nav_menu_items, but I can't seem to retrieve the post_thumbnail.

The original code I had (snippet):

if (have_posts()) : while (have_posts()) : the_post();
    $image = wp_get_attachment_image_src(get_post_thumbnail_id());
endwhile; endif;?>

My new code:

$menu = wp_get_nav_menu_items('Homepage blokken');
foreach($menu AS $m){
     echo $m->ID; // this echoes the correct ID
     $pThumbId = get_post_thumbnail_id($m->ID); // this returns empty
} ?>

Why is this not working?


Dammit, I just discovered that the $m->ID I was using wasn't actually the post->ID, but the menu->ID. I used $m->object_id to fix the issue. Hope this will help someone in the future :-S

|improve this answer|||||

Please use this code, you will get the exact output:

foreach ( $items as $el ) {
    if ( $el->post_parent == $parent ) {
                'id'   => $el->object_id,
                'text' => $el->title,
                'url'  => $el->url

Not the answer you're looking for? Browse other questions tagged or ask your own question.