BuddyDev

Search

[Resolved] Featured Images in MediaPress?

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #4674

    Hello,

    I have an assortment of pages that utilize MediaPress for an image slideshow.
    Each page is designated towards a registered user, and therefore I have a php script that automatically inserts the MediaPress shortcode along with the User’s ID. –> “[mpp-list-media user_id=.$variable.]”

    The images show up appropriately on the page, but WordPress is not acknowledging the fact that the post has images in it or more specifically a featured image based off a MediaPress gallery.

    Is there a way to automatically assign a Featured Image to a post from a MediaPress gallery?

    Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4678

    Hi Brian,
    MediaPress images are normal WordPress attachment.

    You can use set_post_thumbnail() on any of these atatchment to set them as the featured image.

    Reference : https://codex.wordpress.org/Function_Reference/set_post_thumbnail

    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #4689

    Thank you Brajesh.

    Correct me if I’m wrong, but since I am using the shortcode ‘[mpp-list-media user_id=.$variable.]’ in the post, and not directly attaching MediaPress images to the post itself, it is not acting like a normal WordPress attachment.
    More specifically, users add images to their BuddyPress profile, and the shortcode is assigned to their individual post.

    Anyways,
    Usage for ‘set_post_thumbnail()’ is as followed:

    <?php set_post_thumbnail( $post, $thumbnail_id ); ?>

    Getting the Post ID for $post is easy ($post = get_the_ID();)

    But I am confused on obtaining the thumbnail id for the MediaPress image.

    I am able to retrieve the Image URL by doing the following:
    $thumb_url = mpp_media_src( ‘full’ );
    echo $thumb_url[0];

    But this does not help me in finding the thumbnail ID..

    Any advice on how to obtain a thumbnail ID from MediaPress shortcode gallery?

    My apologies if this is a noob question.. I am somewhat new to WordPress and PHP. Spent several hours trying to wrap my head around this but still confused.

    TY 🙂

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #4693

    Hello,

    I was able to find thumbnail ID via the following,

    in functions.php:

    function get_attachment_id_from_src ($image_src) {
    global $wpdb;
    $query = “SELECT ID FROM {$wpdb->posts} WHERE guid=’$image_src'”;
    $id = $wpdb->get_var($query);
    return $id;
    }

    then on page:

    $thumb_id = get_attachment_id_from_src($thumb_url);

    It’s weird… I stumble for hours one day, only to come back to it the next and immediately stumble upon the answer

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #4694

    Actually, I’ve encountered another problem.

    It seems my function is not returning correct thumbnail id from image url.

    I checked manually and the thumbnail id for the image I’m getting through the url and it is ‘3447’

    $thumb_id = get_attachment_id_from_src($thumb_url);

    $thumb_id is for some reason outputting an ID of 1627. Not sure where it is getting this ID from, but it is not correct and not working because of this..

    Still looking into this.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4695

    Hi Brian,
    My apologies for the delayed reply.

    Please use

    
    mpp_get_media_id() 
    
    

    It will give you the current media in the loop.
    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #4697

    Perfect, thank you!
    Works great.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #4698

    You are most welcome 🙂

The topic ‘ [Resolved] Featured Images in MediaPress?’ is closed to new replies.

This topic is: resolved