Can’t get or display post thumbnail in wordpress

Please notice, has_post_thumbnail() does not only check to see if the post has a featured image, but also checks if there is an image in the post itself. There is a quote from WordPress Code Reference: It’s worth noting that has_post_thumbnail() does not just check for the Featured Image as the Codex User Contributed Note … Read more

Display post thumbnail after clicking on post id with AJAX

You can start by trying this. 1. Change this <span class=”id_53″>Display Post Image</span> to <span class=”id_53″ data-id=”53″>Display Post Image</span> 2. Create you js file $(function () { // click event example $(‘.id_53’).on(‘click’, getThumb); // call the ajax function getThumb() { $.post( ‘http://path/wp-content/themes/your-theme/ajax-file.php’ , ‘my_id=’+$(this).attr(‘data-id’) , showThumb ); } // get image source function showThumb(e) { … Read more

How to filter wp_get_recent_posts() to only posts that have thumbnails?

You can pass arguments to pass meta_query to your wp_get_recent_posts() function. wp_get_recent_posts() makes call for get_posts(), so you can make use of all the arguments get_posts() or WP_Query uses. As per your need. $args= array( ‘meta_query’ => array(array(‘key’ => ‘_thumbnail_id’)) ); $recent_posts = wp_get_recent_posts($args); Along with other arguments you want to pass to your function. … Read more

Using custom field to change alt text for a featured image

I think you gave the answer in your last comment. if (get_field(‘alt_image_f’)){ $post_thumbnail_attr = array(‘alt’ => get_field(‘alt_image_f’) ); the_post_thumbnail( ‘full’, $post_thumbnail_attr ); } else the_post_thumbnail(); Cleaning up your code a bit, the following should work $custom_image_alt = get_field(‘alt_image_f’); $post_thumbnail_attr = array(); if ($custom_image_alt) { $post_thumbnail_attr[‘alt’] = $custom_image_alt; } the_post_thumbnail(‘full’, $post_thumbnail_attr);