This says it’s resolved. How did you resolve it?
It has been a little while since I figured this out but I accessed a function (get_post_thumbnail_url) located within the “MultiPostThumbnails” class in multi-post-thumbnails.php.
I was using this in a custom post type and the following line was located within The Loop.
$secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('POST-TYPE','secondary-image');
Thanks for the quick reply. I don’t think that function exists in that plugin. I know it does for WordPress, but not the plugin itself. Are you sure this is how you did it? It doesn’t work for me.
Well I remember, now, that the plugin author had given me a link to a build of the plugin that had not, and I guess still hasn’t, been released.
I’ll mark this as unresolved again and maybe that will prompt the author to reply.
This was likely due to some version issues. 1.0 was just released so an update should get it.
Is there anyway retrive URL path only from this function??? <?php
echo MultiPostThumbnails::the_post_thumbnail(‘casestudy’, ‘image2’); ?>
This below is what I want achieve URL path is missing from href
[ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]
<?php if (class_exists('MultiPostThumbnails')
&& MultiPostThumbnails::has_post_thumbnail('casestudy', 'image2')) : ?>
<a href=""> <?php MultiPostThumbnails::the_post_thumbnail('casestudy', 'image2', NULL, 'post-image2-thumbnail'); ?></a>
<?php endif; ?>
Thanks in advance
`
<?php if (class_exists(‘MultiPostThumbnails’)
&& MultiPostThumbnails::has_post_thumbnail(‘casestudy’, ‘image2’)) : ?>
<a class=”lightbox” href=”” > <?php MultiPostThumbnails::the_post_thumbnail(‘casestudy’, ‘image2’, NULL, ‘post-image2-thumbnail’); ?></a>
<?php endif; ?>
@mikizzi
As noted above, the MultiPostThumbnails::get_post_thumbnail_url() function should do it. Likely MultiPostThumbnails::get_post_thumbnail_url('casestudy', 'image2') will work based on what you have above.
got it ! thanks for replying!!
Hey Chris,
I’m trying to use the code about by mikizzi, but I am a little confused…
<?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('product-item', 'primary-image')) : ?>
<a href="#">
<?php MultiPostThumbnails::get_post_thumbnail_url('product-item', 'primary-image'); ?>
</a>
<?php endif; ?>
Is this correct? This is on an individual post page.
Thanks!
How would I retrieve the url of a custom image size since get_post_thumbnail_url doesn’t support image name?
I came up with this workaround for anyone interested.
Note: In this example I used a foreach loop. It’s definitely not required. But I needed multiple image URL.
<?php
$slider_sizes = array(
"portfolio-slide-large",
"portfolio-slide-med",
"portfolio-slide-small"
);
foreach ($slider_sizes as $slider_size) {
$attachment_id = get_post_meta($post->ID, 'portfolio_secondary-image_thumbnail_id', true);
$url = wp_get_attachment_image_src( $attachment_id, $slider_size );
$slider_src[] = $url[0];
}
?>
@scott you can pass the size in to MultiPostThumbnails::get_the_post_thumbnail() as the fourth arg. See the function signature:
public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' , $link_to_original = false)
My secondary thumbnail is called main-image.
I would like to return the URL of the image being used for the thumbnail to use to link to it from the thumbnail. I am not able to get get_post_thumbnail_url to return the URL.
Here is what I have tried as a starting point, but it is returning an empty href=””. Any help appreciated. I also posted this to another question which suggests there might be a slightly different way to do this, I am trying two different ways, so not trying to overpost.
<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::
$secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('POST-TYPE','main-image');
echo '<a href="' . $secondary_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox" >';
the_post_thumbnail(get_post_type(), 'main-image',NULL, 'medium');
echo '</a>';
endif; ?>