The get_the_post_thumbnail()
internally uses the global $post
to get the post ID. That is why the code works while you are getting errors. it’s not required to pass the post ID to this function, so you can pass null
to it.
But the error is because there is no defined $post_ID
variable. If you want to get the post’s ID, you should either use global $post; $post->ID;
, or better use get_the_ID()
.
Related Posts:
- Query posts only with featured image
- In loop: posts have thumbnail AND other variables
- 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?
- 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
- How can I check for a thumbnail in WordPress?
- 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
- the_post_thumbnail do 2 queries. How to optimize
- Featured images loop for Orbit Slider
- how to put thumbnail below category’s title?
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- Featured Image as Background with Offset
- Trying to use “Medium” featured image for custom post type on home page
- wp_get_attachment_image not to get the post_thumbnaill
- Featured image not showing on page
- Display First posts without the default featured image
- Display only posts with thumbnails
- why ignore_sticky_posts in sticky post query
- WP_Query by post ID doesn’t work if post is in custom post_status
- Tracing the life of a query
- WP_Query orderby taxonomy term value (numeric)
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- WP Query and order by particular specified IDs
- Get the post permalink within the loop but without additional DB query
- Display revision if post status is pending
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP Query search for attachments and their exact title
- How to add another parameters to WP_Query?
- Display link to taxonomy archive only if it has posts with certain custom field values
- How to display posts month by month?
- Programmatically set ‘meta_query’ for filter
- Display posts with date wordpress default
- WP Query Exclude and Start by Menu Order Offset
- Query total number of posts
- Category attribute not working in custom shortcode
- WP_Query Excluding pages with Order is 0
- How to display a posts 1 year ago with custom WP_Query loop?
- Check on which page specific result exist
- WC displaying products from category
- Display custom field meta outside loop, site wide
- Where is the WP_Query instance instantiated (when working with themes)?
- Iterating through $wpdb query without using get_results for large query results
- Extend product search with meta in WooCommerce
- Custom wp_query for related posts with cmb2
- Include data from custom table in WP_Query
- Query posts by last comments
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- Conflict with get_posts and the_content
- Does wp track views for posts?
- WP_query exclude posts of a format
- Custom query with meta_key not working fine
- Can I simplify in function column_default use of queries
- how to get wordpress user id when user register
- Highlight post in sidebar on single page
- Specify strict ‘order by’ in WordPress query
- How to set up hierarchical relationships without using plugins / meta query
- Single field to search for matches on post ID or meta values
- Meta query compare for ID’s greater than specific ID
- Slider won’t work with custom query
- wordpress udpate query not equal to
- How to generate feed for custom template
- Why does apply_filters behave different inside and outside a loop?
- Having a variable based on $post_count increase when i move to the next page of results
- Post order by custom fields
- WP Query and multiple pages
- Elementor posts custom query based on tag [closed]
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- How do you do a meta query on an encrypted field?
- Multiple WP_Query args combinations according to post type
- in_the_loop() issue with custom query
- Pagination inside the blog page not working
- How to restrict add media library only to images of the same post family?
- Wp Query sort order
- get_posts query caching?
- Adding additional taxonomies to wordpress taxonomy page
- why doesn’t this pre_get_posts code work?
- pre_get_posts with WP_Query to prevent posts from specific tags
- Best way to Order Post in Home without a plugin
- Retrieving category pages from subcategory returns empty sets
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- Get post closest to today
- Get WP_Query query after execution?
- Pagination in custom query not working [duplicate]
- $query_args for loop to only get posts from “current category”?
- 294 Queries on Mainpage of WordPress
- I want to place a post before all others from an ACF boleen field
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- wp_query, calculate with two dates when ‘key’ is text format