Reputation: 308
I search internet, but I found only the reverse scenerio, the thing I want to do is that get only featured image in this query
$attachments = new WP_Query( array(
'post_parent__in' => $published,
'post_type' => 'attachment',
'post_status' => 'inherit',
'fields' => 'ids',
'posts_per_page' => 1,
'orderby' => 'rand',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'no_found_rows' => true
) );
if ( $attachments->have_posts() ) {
$image = wp_get_attachment_image_src( $attachments->posts[0], $args[ 'size' ] );
if ( file_exists( $image[0] ) ) {
set_transient( $objects_key, $image, 3 * HOUR_IN_SECONDS );
}
}
}
Upvotes: 0
Views: 47
Reputation: 2588
You really don't want to mess with wp_query() if you can help it try this...
global $post;
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
if($post_thumbnail_id != null) {
$image = wp_get_attachment_image_src( $post_thumbnail_id, $args[ 'size' ] );
if ( file_exists( $image[0] ) ) {
set_transient( $objects_key, $image, 3 * HOUR_IN_SECONDS );
}
}
I am asuming that $objects_key and HOUR_IN_SECONDS are defined elsewhere
Upvotes: 1