Question

I'm trying to get this code to pull only the "stills" category on my Wordpress page. I tried a few different things but it just pulls all of the category thumbnails.

<?php
$args = array( 'numberposts' => '12' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    if ( has_post_thumbnail($recent["ID"])) {
        echo '<li>' . get_the_post_thumbnail($recent["ID"], 'thumbnail') . '</li>';
    }
}?>
Was it helpful?

Solution

You can try:

<?php
$args = array( 'numberposts' => '12' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
  if ( has_post_thumbnail() ) {
    if (is_category('stills')){
      the_post_thumbnail( 'thumbnail' );
    }
  }
}?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top