can't get featured image url using get_post_meta (7 posts)

  1. misthero
    Posted 5 years ago #

    I need to get the url of a thumbnail to create a link.

    this is what happen:

    I have set some thumbnail size in my function php like this:

    add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 226, 135 );
    	add_image_size( 'gallery-link', 96, 60, true ); gallerie
    	add_image_size( 'gallery-preview', 400, 350, true );
    	add_image_size( 'gallery-full', 900, 9999, false );

    then I have a page with a custom loop:

    <?php $preview_img = new WP_Query('post_type=pictures&posts_per_page=18'); ?>
    <?php while ($preview_img->have_posts()) : $preview_img->the_post(); ?>

    an inside the loop I want to link the medium thumbnail to the large one so that cicking on the first the second will be opened in a shadowbox:

    <a href="<?php echo get_post_meta($post->ID, 'gallery-full' , true); ?>" rel="shadowbox">
    <?php the_post_thumbnail('gallery-preview'); ?>

    now I'm gettin the medium picture "gallery-preview" but in the generated html it links to nothing, this is what i can see in the page source:

    <a href="" rel="shadowbox"><img src=".. etc

    why the href is empty??

    I have tested to echo the $post->ID and it works giving the correct post ID.
    what am I doing wrong??

    (the strange thing is that I'm using the exact same code in another blog and it works there...)

  2. luke@VE
    Posted 4 years ago #


    I am having the same problem.. I want to use the featured image URL, but I don't want to dive into all the mess to get it.

    I think I am going to use the hack I came up with. Its not pretty but it gets the job done:

                echo $matches[0] [0];
  3. luke@VE
    Posted 4 years ago #


    I think this works better:

    $featured_img=explode('www', get_attached_file(get_post_thumbnail_id()));
    $featured_img=get_bloginfo('url') . $featured_img[1];

    Execute the code inside the loop.

  4. misthero
    Posted 4 years ago #

    if you have something like this:

    add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 226, 135 );
    	add_image_size( 'gallery-link', 96, 60, true ); gallerie

    you can use inside your loop:

    <!-- get url for thumbnail gallery-link -->
    <?php $galleryurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'gallery-link' ); ?>

    and use it like this:
    <a href="<?php echo $galleryurl[0]; ?>" > link </a>

  5. srichand
    Posted 4 years ago #

    Hi misthero,

    The code did the work , thanks man.

  6. Frankie Jarrett
    Posted 4 years ago #

    @misthero thank you very much

  7. norte m
    Posted 4 years ago #


    I am using a WP theme that has featured tabs
    (http://www.elegantthemes.com/preview/MyProduct/) those 3 grey tabs show featured content, but the featured image on those tabs comes from the wodpress featured image.

    I want the featured image to come from a get_post_meta like the tab tittle, but i am not sure on how to chnage the code... can anyone help me?

    $arr[$i]["tabtitle"] = get_post_meta($post->ID, 'Tab', $single = true);
    		$arr[$i]["permalink"] = get_permalink();
    		$arr[$i]["thumbnail"] = get_thumbnail($width,$height,'thumbnail alignleft',$arr[$i]["fulltitle"],$arr[$i]["tabtitle"]);
    		$arr[$i]["thumb"] = $arr[$i]["thumbnail"]["thumb"];
    		$arr[$i]["use_timthumb"] = $arr[$i]["thumbnail"]["use_timthumb"];
    		$ids[]= $post->ID;
    	endwhile; wp_reset_query();	?>

Topic Closed

This topic has been closed to new replies.

About this Topic