Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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):

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

My new code:

<?php
$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
add comment

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.

2 Answers

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
add comment

Please use the code you will get the exact output

$items = wp_get_nav_menu_items();

    foreach($items as $el){
        if ($el->post_parent == $parent){
            array_push($ret,
            array(
            'id' => $el->object_id,
            'text' => $el->title,
            'url' => $el->url
            ));
        }
    }
share|improve this answer
add comment

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