How to Get All Post Attachments in WordPress Except for Featured Image


How to Get All Post Attachments in WordPress Except for Featured Image
Lucy Franklin

The code above first checks if the post type is data-design and the post status is published. You may not need the first conditional depending on what you are trying to do. Then we simply run the get_posts query. Everything is pretty self explanatory there. The key that we must highlight is the exclude feature. That line is making sure that featured image does not show up. If you take that line away, then the featured image will show up. After specifying all the parameters, we simply specify what to do when each attachment is pulled. We are pulling attachment type for the class variable. Then the $thumbimg variable is simply using wp_get_attachment_link to pull the image at a specific thumbnail size, and it also hyperlinks the image to the single attachment pages. In the final step, we simply echo it.

Be the first to comment

Leave a Reply

Your email address will not be published.


*