Depending of what you are exactly trying to achieve accessing the first element of the $posts
array may work for you. No need for the foreach
loop.
echo '<img src="'.$posts[0]['img']['url'].'">';
Related Posts:
- Get the id of all images in a post
- Inject post (from specific category) between posts in Loop
- Permanently remove first image from posts
- Looping through WP_Post Object
- Using a javascript file to access a get posts array
- Styling images coming from another blog
- Must Use Plugin Causing Query Error
- How can I add multiple ‘tax_query’ arrays via a loop?
- Cannot display or echo alt text on featured image
- Recent posts with featured image or fallback image with permalink
- Best practice for migration friendly images in posts/pages?
- Reprinting tags with all attributes
- How can I add extra word in permalink when someone click download button?
- remove post that has no content
- Checking array against author id in loop
- Redirect to another page using contact form 7? [closed]
- How to loop through all the attached images in a post, and get their url one by one
- How to avoid duplicates when creating recent network posts
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- How to get the last category name of a child category?
- WordPress query undefined offset in loop
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Get all posts as an array ID => Name
- I’m unable to call img path using single quotes in an array?
- Do not duplicate posts with multiple categories in multiple loops
- how to make an array of post id’s in is_single
- array_rand not working correctly?
- How to pick “full/thumbnail” images in the loop?
- Update value of a associative array with update_post_meta
- Wp Query : Order by distance lat,lon
- Display articles with a different template in the home page | Solved |
- in_array not working on dev server but works on localhost
- Is there anyway I can call the year once?
- ACF – Get ID of relationship field in flexible content
- Show the subcategory name based on current product
- Get list of posts from attachment
- How do if all posts has this category ID then do this
- Make sticky post with FacetWP
- Get current_post in reverse order with pagination
- what’s the syntax for if the image exists get the image?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Add div after every 4 posts then every 2 posts for a responsive loop
- Insert div after every three posts in home.php [duplicate]
- Retrieving specific images from Media Library
- WP_Post is not from correct array
- Create Customization Controls from Array
- Automatically create a loop for post ID
- Excerpt all post content Content Same Size without word cutting off
- How to create a loop that will display one post and stop?
- WooCommerce: write featured image dimensions to custom fields in product’
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- How can I fetch loop of post titles via AJAX?
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- Handling an Ajax form submit
- Custom Loop through category menu to include sub categories
- Custom excerpt function re-factoring
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- ‘orderby’ => ‘rand’ alternative for better performance?
- How to get media objects
- How Display Posts on category
- How to get specific image in media library with php
- hover image appears below placeholder instead of overlayed
- Add custom url to featured image
- Split loop into two columns, how to favor one side over the other
- Filter Select results based on selection
- Upload multiple images to a Woocomerce product
- How to show only subcategories in parent category not parent category?
- Get post id within comments loop
- Syntax error when I try to insert my loop into an unordered list? [closed]
- How to overwrite orderby with add_query_var
- Get latest post from all categories except one
- Parse error: syntax error, unexpected end of file
- How can I remove the first two words and shorten get_the_title()
- Where are the src and srcset sizes coming from?
- Echoing a CSS class based on category of post in a list
- Get featured image with custom size outside WordPress
- How to Make Thumbnail of Post Stay Animated
- CSS images don’t show up with bloginfo
- Custom functions for string data calculations
- How to show categories and date on posts
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Prepend to all image URLs with PHP, only for mobile devices
- Check if current post in loop is last on current page
- Check the database for a postmeta field
- Send Notification after post published was working but stopped after the last WP update
- adding or removing endforeach; throws error!
- Combine multiple queries, array_unique returns nothing
- Get a list of tags present in a paged front page
- WordPress while loop with aphabetic counting like one, two, three
- Get posts associated with media attachment
- Auto remove empty values in array
- I want my wordpress loop to only display posts of the standard format
- How to use custom fields to replace top-level parent title with an image using wp_list_pages?
- Query posts by custom fields (object post)
- add if statement to the featured image
- bloginfo url in javascript
- How do I exclude the current post from the upcoming post query
- PHP how to submit array elements to database
- Adding caption to all images inside an article