wp_query and featured image problem
-
I’m having a very hard time getting a custom loop to display posts if they have a featured image associated with it. After fifty different variations, I’m lost, and would really appreciate it if anyone can guide me about what it is that I’m doing wrong.
Here is my code:
<?php $query = new WP_Query( array( 'post_type' => array( 'post', 'page' ) ) ); ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <?php if ( has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <?php the_post_thumbnail( array( 1000, 315), array( 'class' => 'slideshow-img' ) ) ?></a> <?php endif; ?> <?php endwhile; ?> <?php wp_reset_postdata(); ?>
I’m querying to see if a certain post/page has a featured image with this code.
I used the exact same variation but with the get_posts() function and that worked perfectly, however, it doesn’t show any pages with featured images, hence a dead end again.
Is there anything I’m doing wrong? Without the post thumbnail condition, the query works. Is there anything I’m missing?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘wp_query and featured image problem’ is closed to new replies.