Skip to content

Frequently Asked Questions

Chris Scott edited this page Jul 30, 2014 · 2 revisions

I'm trying to upgrade to a new versions of WordPress and get an error about MultiPostThumbnails

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.

How do I register the same thumbnail for multiple post types?

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
                    )
                );
            }
        }

How do I use a custom thumbnail size in my theme?

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.

How can I get the thumbnail without automatically echoing it?

Use MultiPostThumbnails::get_the_post_thumbnail() in place of MultiPostThumbnails::the_post_thumbnail().

How do I get just the URL of a thumbnail without the wrapping HTML?

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');

When I use the sample code the thumbnail doesn't show up. What's wrong?

  • 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 or waffles?

Pancakes.