How to Add Multiple Featured Images for a Custom Post Type
- September 23, 2016
- Leave a comment
WordPress supports only one featured image by default for a custom post type or default post. But you can extend it to display multiple featured images as per your requirement.
Sometimes, you may want to display more than one featured image. Let’s assume you want to display a slideshow of a specific car (here, car is a custom post type). Some libraries and plug-ins can do it for you; the most common among them is “Multiple Post Thumbnails”. You need to extract its files and then include them in your Theme.
After that, you need to upload some additional featured images and associate them with the custom post type by using the following code:
'label'=>'2nd Feature Image',
'label'=>'3rd Feature Image',
You have successfully added support for three featured images to your ‘cars’ custom post type. Use the following code to get the image source at the front-end:
$img_name ='feature-image-2'; //And so on
$img_id= MultiPostThumbnails::get_post_thumbnail_id(‘cars’,$img_name,$post->ID );
// use the MultiPostThumbnails to get the image ID
// define full size src based on image ID
After getting the image source for all the featured images, pass them onto a slider or carousel accordingly.
3 thoughts on “How to Add Multiple Featured Images for a Custom Post Type”
i use this code for multiple featured image for custom post type but its not working..
Just to be clear have you installed “Multiple Post Thumbnails” plugin? if not then this code is not valid without that.
Make sure the plugin is updated.
Let us know if you need further assistance.
Azeem | Client Service Executive
I use this code but it doesn’t work. I add multiple post thumbnail plugin also. But I am unable to display featured image on my custom post type page.