Support » Themes and Templates » get_post_meta doesn't work when creating a Widget

  • For some reason, when I try and use get_post_meta in a widget I’m creating, it doesn’t work. It isn’t pulling in the data. Here’s my code:

    <?php query_posts('posts_per_page=1&meta_key=ll_trendingvideos&meta_value=yes');
    	if (have_posts()) : while (have_posts()) : the_post();
    	$videoembed = get_post_meta($post->ID, 'll_videoembedcode', true); ?>
    
    	<p><?php the_title(); ?></p>
    	<?php echo $videoembed; ?>	
    
    	<?php endwhile;
    		   endif;
    		   wp_reset_query(); ?>

    While the_title works, the custom field is not displayed. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    does this extracted code work, for instance, in single.php within the loop?

    <?php $videoembed = get_post_meta($post->ID, 'll_videoembedcode', true); ?>
    	<?php echo $videoembed; ?>

    Sure does alchymyth, the code works perfectly in all template files, including sidebar.php where the call for the widgets bar resides.

    Just won’t give me any output when attempting to create it as a widget.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta doesn't work when creating a Widget’ is closed to new replies.