the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?

I have 2 authors and an admin on my blog.
I am using the following code in my contributors.php

function contributors() {
        global $wpdb;

        $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");

        foreach($authors as $author) {

        echo the_author_image($author->ID);

        echo the_author_meta('display_name', $author->ID) . '</br>' ;
        echo the_author_meta('user_url', $author->ID) . '</br>';
        echo the_author_meta('description', $author->ID) . '</br>' ;
        echo the_author_meta('user_email', $author->ID) . '</br></br>' ;

        }
        }

        contributors();

It’s printing all authors’ and admin’s photo, name, description and email perfectly.

Read More

but it not printing the user link correctly.

  • for admin or user ID 1 it’s printing the blog URL
  • for 1st author or user ID 2, it’s printing the correct URL.
  • for 2nd author or user ID 3, it’s printing nothing.

what is the problem? how can I solve this?

Related posts

1 comment

  1. Have you checked the database for User’s url. Maybe that’s what they used for registering.

    What about this scenario –

    • For admin, the default value of url is the blog url.
    • User ID 2 used a url when registering.
    • User ID 3 kept the url field blank when registering.

    You should fist check their url from the database. It resides in wp_users table(I am assuming that you have used the table prefix wp_).

    EDIT:

    the_author_posts_link() and the_author_meta('user_url',$userID) have different functionality.

    the_author_posts_link() display displays a link to all posts by an author.

    the_author_meta('user_url',$userID) displays their homepage url.

    So, these are two different things. I think your best bet is to use the following to get what you are trying to achevie instead of the_author_meta('user_url', $userID). You can’t also use the_author_posts_link as it takes no argument and have to be used inside The Loop:

    <a href="<?php echo get_author_posts_url( $author->ID ); ?>"><?php the_author_meta( 'display_name', $author->ID ); ?></a>
    

Comments are closed.