I used this great one liner code to display with comma separated ID numbers of all attached images to a post. But I couldnt extract the featured image ID from it. How can I extract the featured image ID by using and adding this nice code?

$ids = join( ',', wp_list_pluck( get_attached_media('image' ), 'ID' ) );

got from How do I create Comma Separated list of attached image ids?

1 Answer 1


If we want to exclude the featured post image then here's the one-liner updated:

$ids = join( ',', wp_filter_object_list( get_attached_media('image' ), [ 'ID' => get_post_thumbnail_id() ], 'NOT', 'ID' ) );

here it's expanded:

$ids = join( 
    ',',                                       // join array by comma
        get_attached_media('image' ),          // fetch attached images
        [ 'ID' => get_post_thumbnail_id() ],   // filter ID equal to featured image ID
        ' NOT',                                // filter operator: NOT
        'ID'                                   // pluck the IDs (only include)

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.