简体   繁体   中英

Getting wordpress author image url issue

I am having trouble understanding why I can't get the author url to work. I am getting the gravatar uri but the image is not showing.

Here is what is being displayed in the html code:

<div class="authorBackgroundImg slick-slide" style="background: url(&quot;http://1.gravatar.com/avatar/d098d4e8?s=96&amp;d=mm&amp;r=g&quot;) 0% 0% / cover no-repeat; height: 445px; position: relative; width: 217px;" data-slick-index="5" aria-hidden="true" tabindex="-1" role="option" aria-describedby="slick-slide05">

Here is what the php code looks like to retrieve the avatar url:

$profileImgUrl = get_avatar_url( $userId, '500' );

Here is the query for the wordpress database:

$queryAuthorVals = "
                SELECT DISTINCT {$wpdb->prefix}users.display_name, {$wpdb->prefix}users.ID, {$wpdb->prefix}posts.post_author
                FROM {$wpdb->prefix}users, {$wpdb->prefix}posts
                LEFT JOIN {$wpdb->prefix}term_relationships rel ON rel.object_id = {$wpdb->prefix}posts.ID
                LEFT JOIN {$wpdb->prefix}term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id
                LEFT JOIN {$wpdb->prefix}terms t ON t.term_id = tax.term_id
                WHERE {$wpdb->prefix}posts.post_author = {$wpdb->prefix}users.ID
                AND {$wpdb->prefix}posts.post_type = 'post'
                ORDER BY {$wpdb->prefix}users.display_name ASC
            ";

            $postAuthors = $wpdb->get_results($queryAuthorVals, OBJECT);

"Note" I have removed part of the id from the users avatar url ' http://1.gravatar.com/avatar/d098d4e8?s=96&d=mm&r=g ' but it shows the avatar when I put the url in the browser. Also I can display the <img /> element with get_avatar( $userId, '500' ); but this is not what I want to do.

Anyone know how to fix this, I can't seem to find a solution on google.

Cheers

OK so I figured it out, because I'm using the ultimate member plugin I have got it to work by using the ultimate member functions

$ultimatemember->user->set( $userId );//set the user id
$userAvatar = um_get_avatar_uri( um_profile('profile_photo'), 400 );//get the user avatar based on the current user id.

I tried this earlier but didn't use the set user function $ultimatemember->user->set( $userId ); so it was grabbing my avatar for each author image as I'm building a custom authors slider.

Hope this helps someone else :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM