Managed to find a solution that display the array correctly:
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
$imgArray = array();
$counter = 0;
foreach ( $attachments as $attachment_id => $attachment ) {
$imgArray[$counter] = $attachment_id;
$counter++;
if($counter > 2) {
break;
}
}
?>
<div class="attachment1"><?php echo wp_get_attachment_image( $imgArray[0], 'medium'); ?></div>
<div class="attachment2"><?php echo wp_get_attachment_image( $imgArray[1], 'medium'); ?></div>
<div class="attachment3"><?php echo wp_get_attachment_image( $imgArray[2], 'medium'); ?></div>
Related Posts:
- add_image_size() for specific Post Types
- Creating an Image-Centric Custom Post Type?
- How to disable generation of default image sizes for some custom post types?
- Order by & include array by specific post ids
- Get list of all registered post types slugs
- List most recent image uploads, but only for specific custom post type
- set_post_thumbnail_size in percent, not pixels?
- How to add a CSS class to every image in a Custom Post Type
- Custom post type Admin Page
- Limit the post for differents custom post type in the same wp_query
- Extract image src from a post and send it to an external form
- Removing Image Sizes for Custom Post Type
- Count all images of a certain post type
- How to get source of custom meta image?
- Stopping WordPress from Auto Generating Image Files for Sizes
- Automatically adding meta data to posts or multiple query help
- Return Attachments from Custom Post Type
- How to get category image custom post type taxonomy in wordpress?
- Set Custom Image Size Just For Specific Custom Post Type
- Issue to get wp_get_attachment_image with cmb2
- How to rename image at uploading on specific plugin or post-type in WordPress
- How to insert multiple images into a single post within a CPT
- Adding class to featured image
- Change post featured image on hover
- My theme saves their custom post type’s metadata as a serialized array, how to access the keys?
- Custom Image Thumbnails of Different Sizes
- How to move image thumbnails into custom folder for custom post type
- uploading images to specified directories
- Get image post ID in media upload
- Link to full size post thumbnail
- Custom Post Type with image gallery
- Multiple featured sizes / images / excerpts
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- How to Create an Image Upload Box for Custom Posts?
- How to store multiple values in 1 meta_key with radio input?
- Add custom image size for custom post type or taxonomy
- Display a CPT based on a metabox selection
- How to automatically set ‘default image size’ for specific Custom Post Type
- Problem: wp_query outputs all images on site
- Display post content with respect to its title?
- Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
- Problems with image size on the server WordPress
- frontend image post uploader
- Limit the post for differents custom post type in the same wp_query
- How to handle large number of images in a post?
- Redirect to another page using contact form 7? [closed]
- How to add multiple images to a custom post type without plugin [closed]
- Custom Post Types — $args vs. labels array
- How can i link a custom post type thumbnail to intermediate size
- Get an array wich contains the post_name of every post that has the custom post_type “pelicula”
- Add first letter of titles to array, then compare arrays
- Query Custom Post Types with checkboxes
- Create Array from custom post type to display a slider
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- Check if user has comment on current post
- copy images from custom field to another custom field
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- link featured image to external link
- How do I disply an array inside a custom post type?
- Custom Post Type Field Array parsing [closed]
- Getting custom post types to properly display alphabetically
- Thumbnails Not Generating
- Should i use custom post type for a custom footer?
- Returning an image url from its attachment ID using a custom post type plugin
- Images not load on custom post type sidebar, related posts
- Not Able to Add New Class To CPT Attachment Image
- How can I loop at a Specific Taxonomy from a custom post type?
- Update value inside array update_post_meta
- Custom archive page for custom taxonomy and pagination issue
- Get an array of the number of post per year of a custom post type (WordPress)
- Query when is one or several values
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- How can I add image sizes for a specific custom post type?
- Change picture attachment meta of all occurrences of a picture
- Staggering featured post using ‘sticky’
- Dupplication of Custom Post Type while adding attachment
- Media is not showing on post page
- Looping through image object using ACF and CPT UI [SOLVED]
- Multi Photo Upload with Caption on Front End for Custom Post Type
- Displaying image instead of post label in wordpress
- Links Image in “Catalog” Page to Posts
- Convert Custom Post Data to Javascript Array for Autocomplete
- CPT and metabox: create multi checkbox by using array?
- Working with gallery shortcode and get gallery images
- Pulling in Related Posts based on Post Type array
- WordPress custom field images not getting inserted into array
- Meta-Box to add multiple items one at a time and on publish save all
- Custom Post Type Author Array Problem
- taxonomy terms array not working
- Display custom posts in checkbox list
- posting twice from an array?
- How to Create a Frontend Html-list Editable in the Backend?
- Allow authors to create article image
- Add Image field to CPT
- img src not working correctly in custom post type
- Add a background image into a post [closed]
- Using wp_insert_post to create custom posts with ACF image field
- Display custom post type attached media file sizes
- post__in select all custom posts and not the selected array of ids
- How to Create Grey Background for Product Images on Website Display but Retain White Background on Downloaded JPGs?