The MU forums have moved to WordPress.org

SItewide Tags with Post Thumbnail (4 posts)

  1. mlmorg
    Member
    Posted 3 years ago #

    I'm a big fan of the sitewide tags plugin but one of my issues with it was that it would not easily allow me to grab the post thumbnail info (in WP 2.9+). Here's a quick fix I did for myself that I just wanted to share. It basically just grabs the post thumbnail image url's and adds them as post metas.

    Another option would be to use the wp_insert_attachment(), etc. functions (as well as copying over the image files into the directory of the tags blog) so that you could use the_post_thumbnail() function on the tags blog -- that wasn't a big deal to me, though, and this was a quicker fix so I just decided to go this route. Anyway, I hope this is helpful for others...

    Just before the switch_to_blog() function within the sitewide_tags_post() function, add this:


    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    if( $thumbnail_id ) {
    $meta = get_post_meta( $thumbnail_id, '_wp_attachment_metadata' );
    $source_dir = wp_upload_dir();
    foreach( $meta[0]['sizes'] as $key => $value ) {
    $thumbnails[$key] = $source_dir['baseurl'] . '/' . substr($meta[0]['file'], 0, 8) . $value['file'];
    }
    }

    And at the end of the if() statement just before the restore_current_blog() function in that same function add this:


    if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    add_post_meta( $p, $key, $value );
    }
    }

    And finally, at the end of the if() statement of the //editing an old post portion, add this:


    if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    delete_post_meta( $global_post->ID, $key );
    }
    }

  2. andrea_r
    Moderator
    Posted 3 years ago #

    High fives for this. I'm hoping this functionality makes it into the next version of SWT, but the devs, they have been flat out busy. ;)

  3. xyzzy
    Member
    Posted 3 years ago #

    Yes, thank you for this!

  4. nick_bracken
    Member
    Posted 3 years ago #

    Can you possibly be more specific on wheere to add these codings? I tried a few times and it seems I entered them in the wrong place because there was an error and I had to re-install the plug-in.

About this Topic

  • Started 3 years ago by mlmorg
  • Latest reply from nick_bracken