If I assign a featured image to any post in question then it does show
the correct image. I just don’t understand why every post after the
first twelve are using another posts featured image.
I think the problem is that you do not reset $image
if the current post doesn’t have a featured thumbnail.
You should add for example:
<?php
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
else:
$image = array( 'http://example.com/default.jpg' );
endif;
?>
since you are using $image[0]
in your code.
Related Posts:
- List events by month
- Custom post type loops with different page templates
- How do you output custom code between posts in the loop?
- How to append element after thumbnail
- Display custom field of specific post where post title matches variable
- Create a random unique 6 digit number as custom field for custom post type
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Very Slow Page – How to Optimize # of Queries?
- Custom Post Type Loop throws 500 error when used in widget
- How to make sure content doesn’t display if selection is empty
- CPT + CMB2: data not displaying for only first post in loop
- How do i calculate the total of values of custom fields in custom post types?
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Custom Tag Description unable to display just below and outside of the Loop
- Including all post id’s of a custom post type into an array
- How can I group posts by months and years?
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Loop increase number
- Using wp_query to modify the loop in index.php for a CPT
- Control content before and after custom post type loop
- Get data from PHP to JavaScript to set position of each post on front page
- foreach loop inside the loop creating duplicates in output
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- How can I increase the post count for custom post types only?
- Show the categories the current post has
- Fetch data from two custom post types and create multidimensional array for output to html table
- Page that lists publications by classifying them by taxonomy
- CPT loop doesn’t seem to account for post date?
- Pagination not working in custom post type. Help
- when looping through custom post data not appearing
- Accessing download link from the loop with WP Download Manager Pro
- Custom Post Type has wrong label and is not found when called by a loop
- Combine multiple separate lists into one
- Looping to organize and display custom posts by category using PHP and WordPress
- Show parent category and subcategory once in while loop
- WordPress trying to query two custom types to get child from the parent
- Add active class to foundation 6 tabs while looping categories
- Display related post content and custom field content
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Strange behavior on WP_query
- get_post_meta for Custom Post Type ( CPT )
- WordPress query posts by custom post type not workng
- WordPress Custom Post Type and sort by Tags
- Order by custom field attribute
- Looping taxonomy in taxonomy?
- Query Custom Post Type by Tag
- How do I filter a custom post type loop by a field?
- How to show Y number of custom posts after every X normal posts?
- Date archives for custom post type
- How do I redirect all 404 errors of a specific post type to another URL?
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- How to save the checked boxes?
- How to get only one category of custom post type?
- Append taxonomy terms as class names in markup?
- Using WPAlchemy metabox values in another metabox
- GravityForm: Populate Dropdown with custom post type [closed]
- How to output wordpress custom tags separated by comma?
- Remove duplicated values from a loop
- Show Different Header on a Specific Post ID
- Admin notice not displaying
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- I need to add endpoint for wordpress categories
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Display Custom Taxonomy Alphabetically
- Hide a widget inside a div on specific type of post
- Displaying custom field according to date
- Display related custom taxonomy posts in sidebar
- Add additional field to custom post_type
- Conditional for a Single Post That Belongs to a Category?
- custom post for slider
- looping though custom post types and only return results in a given taxonomy
- How to conditionally add Custom Post Type to Front Page
- Create short URL with auto 301 redirect
- get_post_types() can’t get some of my post type
- Creating shortcode id for custom post types
- get custom post type value in header.php [closed]
- Different column width in 2 rows with bootstrap and custom post types-different classes needed
- How can i loop through custom post type according to custom meta field?
- Changing WordPress sort order for returned child pages
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- I’m having trouble with Related Product “tax_query” ‘terms’ value
- Filtering posts based on three taxonomies
- Add extra elements to the_post in a custom post_type
- Visualize info in just custom post_type in theme
- Having issue on Loading Meta Data From CSV to CPT
- Rewrite URL of Specific Post of Custom Type
- How to show terms used only for particular custom post type. Filter creation perpose
- Custom post type with custom taxonomy permalinks
- How to get past and upcoming post by defining date in custom field?
- How to query all custom posts of a certain type and checking what category they have
- Categories and page filtering with pre_get_posts
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- is_singular won’t call my functions?
- loop through custom post-type with two meta_keys
- How to exclude certain portfolios from a loop
- Comments are not working on Custom Post Type
- Just the First Metabox what saves the data!