Issues getting post id in WP_Query
-
I am using WP_Query to pull a specific category of posts and trying to pull an image for each one where there is a custom field set.
This is added in my header.php for a feature at the very top of the site.
Everything works, except for pulling the custom field. It renders as blank which doesn’t let the image load.
<?php // Find the specific category $topcat = get_categories('parent=26&hide_empty'); $mycat = $topcat[0]->cat_ID; // The Query $the_query = new WP_Query('cat='.$mycat); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark"> <img src="<?php echo get_post_meta( $post->ID, 'top_slider', true) ?>" alt="<?php the_title() ?>" /> </a> <?php endwhile; // Reset Post Data wp_reset_postdata(); ?>
Any help would be amazing! Thanks.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Issues getting post id in WP_Query’ is closed to new replies.