-
Notifications
You must be signed in to change notification settings - Fork 63
Frequently Asked Questions
This is caused by using the example in old readmes that didn't do a check for the MultiPostThumbnails
class existing first. This has been corrected in the Installation section.
You can loop through an array of the post types:
if (class_exists('MultiPostThumbnails')) {
$types = array('post', 'page', 'my_post_type');
foreach($types as $type) {
new MultiPostThumbnails(array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => $type
)
);
}
}
After you have registered a new post thumbnail, register a new image size for it. e.g if your post thumbnail id
is secondary-image
and it is for a post
, it probably makes sense to use something like:
add_image_size('post-secondary-image-thumbnail', 250, 150);
This will register a new image size of 250x150 px. Then, when you display the thumbnail in your theme, update the call to MultiPostThumbnails::the_post_thumbnail()
to pass in the image size:
MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL, 'post-secondary-image-thumbnail');
You can register multiple image sizes for a given thumbnail if desired.
Use MultiPostThumbnails::get_the_post_thumbnail()
in place of MultiPostThumbnails::the_post_thumbnail()
.
Use MultiPostThumbnails::get_post_thumbnail_url()
passing in the following arguments:
-
$post_type
- the post type the thumbnail was registered for -
$id
- the ID used to register the thumbnail (not the post ID) -
$post_id
- optional and only needs to be passed in when outside the loop but should be passed in if available when called
For example, for a thumbnail registered with an id
of secondary-image
and post_type
of post
the following would retrieve the thumbnail URL:
MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');
- Make sure you are using the same ID you registered the thumbnail with as the second argument to
MultiPostThumbnails::the_post_thumbnail()
. - If you are trying to get the thumbnail outside of the loop or a single template, you will need to replace
get_post_type()
with the post type you are trying to get the thumbnail for. This is common when trying to use the code in headers/footers/sidebars.
I see the meta box in the admin when editing a post but when I click on 'Set as [label] image' in the media manager, nothing happens and I get a JavaScript console error =
If you are using a symlink to include the plugin directory in your project, the admin js file will not load and cause this. Unfortunately, the solution is to not use symlinks due to the behavior of PHP's __FILE__
Is there a way to show the post meta where the thumbnail IDs are stored in the Custom Fields metabox?
Since version 1.5 these are hidden by default. To unhide them, add add_filter('mpt_unprotect_meta', '__return_true');
to your theme's functions.php
Pancakes.