[ad_1]
I have a post that contains a list of recent posts from another post type. These posts are added daily. I would like the thumbnail of the main, listing page to grab the featured image of the most recent post in the list.
I am (probably obviously) a total hack at programming. I started with the code below but wondering if it needs to happen when a new daily post is created? I am now just confused and hoping for some help. Thanks!
function set_custom_thumbnail( $post_8661, $thumbnail_id ) {
$post_8661 = get_post(8661);
$args = array(
'post_type' => 'wakeup',
'post_status' => 'publish',
'posts_per_page' => 1
);
$new_query = new WP_Query( $args );
if ($new_query->have_posts()) {
while($new_query->have_posts()){
$new_query->the_post();
$thumbnail_id = the_post_thumbnail('thumbnail');
}
wp_reset_postdata();
}
return update_post_meta( $post_8661, '_thumbnail_id', $thumbnail_id );
}
[ad_2]