I’m trying to make a simple widget that displays a list of posts, and is followed by some metadata from each post.
Here is my code:
$eventdate
contains the metadata i need to retrieve.
query_posts('');
if (have_posts()) :
echo "<ul>";
while (have_posts()) : the_post();
$eventdate = get_post_meta($post->ID, 'event-date', true);
echo "<li>".get_the_title()." - ".$eventdate."</li>";
endwhile;
echo "</ul>";
endif;
wp_reset_query();
I read an old post on the wordpress support forums about custom loops like this, and I’m fairly certain that I’m not calling the $post_id properly, because if I manually insert a post_id it calls the correct data.. but either way I’m unsure where to go from here. Any help would be appreciated.
query_posts()
is for main query, it would be more wise to useget_posts()
function to get you events.Debugged and realised that $post in $post->ID needed to be declared a global variable. Sorted.