0
votes

I have two featured images on my wordpress custom post type products.

featured and secondary image

I registerd the secondary image with this code:

if (class_exists('MultiPostThumbnails')) {
 new MultiPostThumbnails(
    array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'product'
    )
 );
}

Now I wish to call the secondary image. The Product image is successfully called with this funciton echo get_the_post_thumbnail( $_product->id);

However, I cannot manipulate that wordpress function to fetch the custom Secondary Image instead. I have also tried the_post_thumbnail(); without success, and haven't found another way to grab this.

Edit:

For clarity I want to echo the secondary image on a different page. I tried using the product ID with $_product->id to isolate the specific post this image is related too, however, all the available wordpress functions only fetch the Product image, and I cannot for the life of me get the other images :(

1

1 Answers

2
votes

It's in the FAQ

Register a new thumbnail size (optional)

add_image_size('post-secondary-image-thumbnail', 250, 150);

And then in your theme:

MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL,  'post-secondary-image-thumbnail');

EDIT In light of the modified question, to call the image outside of the loop, and thus specific an ID yourself you need to use the get_the_post_thumbnail() method.

MultiPostThumbnails::get_the_post_thumbnail(
    'product,
    'secondary-image',
    $product->id,
    'post-secondary-image-thumbnail',
    null
)