Instead of using the tag outside, you can echo the output inside the post loop.
And no need to add the $post ->ID because WordPress will automatically pick up the thumbnail with the wp_get_attachment_url() function.
Related Posts:
- Query posts only with featured image
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- In loop: posts have thumbnail AND other variables
- How to adjust found_posts so that it accounts for offset and pagination
- WP Query with offset breaks wp_pagenavi or any pagination
- Exclude first 5 posts of specific categories in the main loop
- Custom query, works, but I get a “Notice: Undefined offset: 0…”
- post thumb nail
- Trying to check and see if a post has a featured image outside of the main loop
- Query sticky posts with thumbnails
- Retrieve featured image (thumbnail) url from multiple posts with one query
- Get image of latest post from taxonomies/categories
- Multiple instances of Featured Image Query
- post thumbnail not showing up with shortcode
- How WordPress attaches its Featured Images with posts?
- Offset Page Loops and Pagination
- How to use offset in WP_Query
- getting post thumbnail within loop causes an error
- How can I fix: “Notice: Undefined offset: 0”?
- WP_Query, pre_get_posts and offset
- WP_Query condition affects posts_per_page count
- Site not getting correct featured image from my query
- Retrieve posts using thumbnail id as meta key
- WP Query – Post Thumbnail
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- How do I rewrite this loop as a new WP_Query style-loop?
- How can I check for a thumbnail in WordPress?
- WP_Query arguments order
- how would i change post->ID to work correctly when querying pages?
- How to display the featured image for each post?
- Query posts only without featured image
- WP_Query – Adding “offset” posts to the end of the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Apply query arguments after the nth post
- AJAX Breaking Offset Argument In WP Query
- Page navigation doesn’t seem to work when I add offset?
- WP_Query offset is returning post from prevois loop
- the_post_thumbnail do 2 queries. How to optimize
- Offset WP_Query by negative 1
- Featured images loop for Orbit Slider
- how to put thumbnail below category’s title?
- setting offset to category number in archive page
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- Using something else instead of using 9 wp_query
- Trying to use “Medium” featured image for custom post type on home page
- wp_get_attachment_image not to get the post_thumbnaill
- WordPress WP_Query offset parameter not working with search parameter
- Featured image not showing on page
- Display First posts without the default featured image
- Display only posts with thumbnails
- Multiple WP_Query with pagination shows Page/2 content on the remaining pages
- How to query for most viewed posts and show top 5
- How to order posts tag by tag?
- Want to redirect if search query match exact title of any post
- Most commented post should be the first post in the blog
- Perform query with meta_value date
- Custom page template query_vars
- Compare two meta-fields in a wp_query (where meta-field-A is larger than meta-field-B)
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- WP_Query class not found
- Exhausted memory limit with very simple WP_Query
- Select from wp_post and multiple meta_value from wp_postmeta
- Multiple Loops Inside a Function
- How to use MySQL’s MATCH AGAINST in WP_Query?
- Ajax Pagination on Ajax filter
- Wp_query returning only one post while query through ajax
- category query for pages not working
- date_query on draft posts only
- How to get list of posts from permalinks?
- Is there a reason why Pages are not publicly_queryable?
- Exclude some authors from query
- apply custom where to the default $wp_query
- wp_query serialised array
- Conditional operator OR not working with custom fields
- Using Transients
- Should I reset $wp_query?
- Sorting search results with custom dropdown
- Posts query according to meta box date
- querying posts with a custom status
- problem with loop
- Query multiple meta key values for template
- How do I get the content of a custom instance of WP_Query?
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Searching not only by post name but also category
- WP_Query, Paginate by Custom Field
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- Search Exact on WordPress – Relevannsi Solution Not Working
- Posts per Page not working
- Get authors list and sort them by recent posts
- Pagination not working in custom loop WP_Query
- Multiple wpostmeta.meta_key
- Saving custom fields for WP_Query to retrieve
- How to take parameters from a function and make them editable as attributes in a shortcode
- WP_Query secondary query failing
- Sorting is not working in WordPress WP_Query
- Add custom WP_Query after the first 3 posts
- Weird results using wp-query with ‘date_query’ for last week
- 1500+ duplicate queries via get_option function (query monitor)
- WordPress Ajax search filter on dropdown select
- after refresh the id that shows correct in first time click, changes to 1