WordPress.org

Ready to get started?Download WordPress

Forums

the_post_thumbnail only displays images a day old (3 posts)

  1. hemlok
    Member
    Posted 1 year ago #

    Well thats about it... I am using the_post_thumbnail with a certain size as a picture slider for my site and everything was working well until I started adding posts, after which the images in the slider disappeared, after playing with them I noticed that the date of the post affected if the thumbnail was displayed or not, my call reads something like this

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            		<?php if ( in_category('3') ) { ?>
    					<a href="<?php the_permalink()?>"><?php the_post_thumbnail('principal');?></a>
    				<?php }
    				endwhile; endif;?>

    Is this expected behavior or am I doing something wrong? I want to display any post that has the featured category which is 3 so I don't see what is wrong please any help would be very appreciated I don't want to be having to change the publication date of the featured posts every day thanks!!

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    I want to display any post that has the featured category which is 3

    you might need to create a custom query to do this - your current code only filters posts with cat 3 from a list of recent posts, possibly limited in number by the dashboard - settings - reading - blog pages show at most [] posts.

    i.e. if the latest post don't have the cat 3, there will be no thumbnail shown.

    if your snippet of code is for showing thumbnails of all recent posts with the category 3 and a thumbnail, then change it to:

    <?php $featured = new WP_Query( array( 'category__in' => array(3), 'posts_per_page' => -1, $meta_key => '_thumbnail_id' ) );
    if ( $featured->have_posts() ) : while ( $featured->have_posts() ) : $featured->the_post(); ?>
    	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('principal'); ?></a>
    <?php endwhile; endif; wp_reset_postdata; ?>

    http://codex.wordpress.org/Class_Reference/WP_Query

  3. hemlok
    Member
    Posted 1 year ago #

    Thanks for the quick answer but actually your code does exactly the same as mine... The number in dashboard - settings - reading - blog pages show at most [] posts I have checked it and it doesn't affect what is displayed in that part of the blog, I have even reduced it to 2 posts and it still displays the featured images, it is after certain date that it stops working, to help me understand how wordpress works since I am new to it let me see if I get this right, when I cycle with if ( have_posts() ) : while ( have_posts() ) : the_post(); it only fetches a certain amount of posts? In theory determined by the the reading settings right? Ok if this is expected behavior great, but I really have a hard time understanding why I can't fetch more posts if that is what the query is for... anyways thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic