0

I'm struggling because I'm using the "Sitewide Tags"-Plugin to grab all posts in a network to the main blog. Now I want to embed the post images to the main blog and the only function you're able to use for that is: the_post_thumbnail ();

But I'm using a grid layout for which I just need the url of the image (src). For that I cant't find the solution and would be very thankful for some help.

Best regards,

Philipp

  • I am not sure how is that plugin influencing the process there. That function calls get_the_post_thumbnail() internally and looking at its source should give you the idea on how data is retrieved and formed. – Rarst Dec 19 '13 at 16:22
  • Thanks! I tried that as well but without success... – Philipp Dec 19 '13 at 16:46
  • get_the_post_thumbnail is correct. If you can't get that working, post the problematic code please. – s_ha_dum Dec 19 '13 at 17:30
  • Thanks again. The problem is, that the plugin doesn't store the image in the post meta itself - As far as I understood. As you can read here (wpmututorials.com/plugins/post-thumbnails-for-sitewide-tags) it's also just possible to grab the "thumbnail" size. What is finde for me at the moment. As the_post_thumbnail(); is the only way (It is, I'm sure), I have to find a way to extract the src from it... :) Thank you very much in advance! – Philipp Dec 19 '13 at 17:43
1

Get post thumbnail url with multisite

If you want to display materials on multisite function without switch_blog_id, then output the image material standard features wordpress fail. For this, I wrote this little function as a turnkey solution is nowhere found.

function multisite_thumb_url($pid, $bid){ //$pid - post id, $bid - blog id 
if(isset($pid) && $pid>0){
    if(isset($bid) && $bid>0){
        global $wpdb;
        $curr_blog_id=get_current_blog_id();
        $wpdb->set_blog_id( $bid );
        $post_thumbnail_id = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_thumbnail_id' AND post_id = {$pid}" );
        $post_thumbnail_metadata = $post_thumbnail_id ? maybe_unserialize( $wpdb->get_var( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND post_id = {$post_thumbnail_id}" ) ) : NULL;
        if ( ! $post_thumbnail_metadata ){
            return false;
        }else{  
            if($bid==1){
                $default_post_thumbnail_url = get_blog_option( $bid, 'siteurl' ).'/wp-content/uploads/'.$post_thumbnail_metadata[ 'file' ];
            }else{
                $default_post_thumbnail_url = get_blog_option( $bid, 'siteurl' ).'/wp-content/uploads/sites/'.$bid.'/'.$post_thumbnail_metadata[ 'file' ];          
            }
            return $default_post_thumbnail_url;
        }
        $wpdb->set_blog_id( $curr_blog_id );
    }else{
        return wp_get_attachment_url( get_post_thumbnail_id($pid) );
    }
}else{
    return wp_get_attachment_url( get_post_thumbnail_id() );
}

}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.