WordPress.org

Ready to get started?Download WordPress

Forums

get_post_meta doesn't work when creating a Widget (3 posts)

  1. Clicknathan
    Member
    Posted 2 years ago #

    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?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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; ?>
  3. Clicknathan
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic