First, exclude the featured image (= post thumbnail) from the query, then set up the posts array as combination of the featured image and the other images.
Put this directly below $args = ...
and above $attachments = ...
:
if (has_post_thumbnail($post->ID)) {
$featured_image = get_post_thumbnail_id($post->ID);
$args['exclude'] = $featured_image;
$attachments = array(get_post($featured_image)) + get_posts($args);
} else
Related Posts:
- Programmatically get images by URL and save in uploads folder
- How to find attachment by it’s name?
- Insert an image into a post by API
- Programatically creating image attachments from local URLs and setting featured image
- Show prev and next post links for parent post of current image in attachment page?
- Exclude images from “inserted into post” when trying to get attachments
- Custom Loop, Match Category with Page: How to display post featured image?
- How do you import images from a URL in your post?
- Custom image size not displaying with wp_get_attachment_image()
- How to echo images Urls from a wordpress post, that are relally in the post
- attachment_fields_to_save first parameter is null
- Troubles with code for upload a image
- attachment.php & flexslider—linking thumbnail to specific image
- How can I use an image from an external source without uploading it to the media library
- How to get image title/alt attribute?
- Get the first image from post content (eg.: hotlinked images)
- Download an image from a webpage to the default uploads folder
- wp_get_attachment_image_src and server path
- Change WordPress image URLs via filter
- get_the_post_thumbnail_url with an unregistered size
- Any easy way to automatically set the first inline image in a post as the thumbnail?
- How can I hide media library images from general users?
- Associate an existing image with a post
- set_post_thumbnail_size not cropping featured images, but reducing proportionally
- How do i upload an image and return the image id?
- Get Attachment ID from URL [duplicate]
- How to change _wp_attachment_metadata specific value in SQL?
- Is it possible to prevent users from uploading small images?
- Can’t Display Featured Image in RSS Feed
- How to upload image without post ID using the new media uploader?
- Applying class to links around self hosted images embedded to posts/pages
- Featured Images on Front Page
- Pulling Post Image Attachments in WordPress 3.9
- Setup A Default Featured Image
- Find posts without featured image? [duplicate]
- How do I add a featured image to a single post page?
- Link Featured Thumb to Attachment Page, If Possible
- Add a featured image in my theme?
- Image still linked as attachment to page even though it has been deleted
- Disable wordpress image sizes generation
- Featured Image .svg height and width 1px only
- Images are randomly deleted from server
- Frontend Post – Allow Only Image File Upload
- Add a new data attribute in tag
- Images not working using Featured post
- Add instructions to featured image
- How do I get more image editing options in the admin?
- Woocommerce featured image of page – not product
- Can’t seem to attach uploaded image to post and set it as thumbnail
- Add an attribute to attachments
- offload media to external services [closed]
- Store Snapshot created via wordpress to use with lightbox
- How to stop thumbnail generation from some images and different size thumbnail generate
- Get attachments for posts that belongs to a specific category
- Does wp_get_attachment_image_src also work with non-image files?
- How do I get my main image to stretch the full length of the screen?
- wp get attachment image always gives me thumbnail
- Filter for post_thumbnail: link to small src and add data-attribute [duplicate]
- Get title of post image is attached to
- How to display original unmodified thumbnail
- One picture belonging different galleries?
- How to set featured image from external url programmatically
- Hide Featured Image box – isn’t working?
- WordPress Attachments with old images
- Set two default featured images
- adding image to post thumbnail from another server
- Set Featured Image not opening – Stuck at loading
- Random Characters in the end of every image url in post
- resize and crop thumbnail photos
- Random Image Script Working but Want to Avoid Duplicates
- Can i have 2 separate Galleries on 2 separate pages each go to a DIFFERENT Attachment.php file?
- How to change an image source when rendering on frontend?
- How to use default image as featured image by implement some code in function.php
- WordPress Multisite: Images moved to /sites/1?
- How to delete original image file after upload and resize
- Image alt attribute
- I cannot upload images to post or the media library in wordpress
- Images missing from Blog post page
- How to disable post-thumbnail from generation?
- second featured post not displaying on page [closed]
- How to Make Only Images Connected to a Post Show? Not Entire Media Collection?
- Delete post if featured image is smaller than Y pixels by Y pixels
- wp_get_attachment_image not to get the post_thumbnaill
- How to force regenerate thumbnails in WordPress posts?
- Url link to feature image in the portfolio [closed]
- Extract url from next_image_link
- Lots of attachments is causing slow load
- How do I get resized thumbnails?
- Making a thumbnail if there exist a link with. jpg or .png extension in WordPress
- Why is WordPress loading a different sized post thumbnail?
- how to display all images from their siblings/ from same parent?
- Title image is missing ( but is not the WP 3.5 issue )
- Images will not attach to posts after site migration
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Using the on-board image editor for featured images: edits are not being used
- Tried everything but Facebook share button won’t load the post thumbnail
- WP is showing wrong image dimensions
- Why some images are not allowed to be edited only for thumbnails?
- Image Attachments Query Not Working If Post Is Loaded Via Ajax
- Attachment tag archive