I am currently trying to set the most recent post's featured image to be the background of my hero image. This is the code I'm using:

<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>

Problem is, it shows the featured image of the most recent most on the entire site. I'm trying to make it use the most recent featured image from a specific category (ID is 42). Could I do something like this:

<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID;cat="45"), 'full' );?>

1 Answer 1


I am not sure where you are trying to do this but give something like this a try.

    $category_id = 45;
    if (have_posts()) : while (have_posts()) : the_post(); 
        $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
    endwhile; endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.