WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

closed as too localized by toscho Dec 27 '12 at 23:26

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 0 down vote accepted

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

share|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
share|improve this answer

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