0

I've created a user list for all the customers who registered on my website. When a outside user (or guest) browse my website and want to view the profile of a specific user, they should be able to click on the user's name and then should be redirected to the profile page of that user. I've managed to set everything up but the link points me to an author page and should point me to the PROFILE page of the user.

Code inside functions.php:

function userlist() {
    global $wpdb;

    $users = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY display_name");

    foreach ($users as $user ) {

        echo "<li>";
        // GETTING USER AVATAR
        echo "<a href=\"".get_bloginfo('url')."/author/";
        the_author_meta('user_nicename', $user->ID);
        echo "/\">";
        echo get_avatar($user->ID);
        echo "</a>";
        // DISPLAY USER-NAME
    echo '<div>';
    echo "<a href=\"".get_user_meta('user_url');
    the_author_meta('user_firstname', $user->ID); // points to wishlist url -> seems like it searches for name 
    echo "/\">";
    the_author_meta('user_lastname', $user->ID); // display name
    echo "</a>";

I've changed the // DISPLAY USERNAME part a bit. When I hover over the username, the link displayed reads: wordpress/user-list/username but when I click on the username it redirects me to the user's wedding registry page which is: http://example.com/wishlist/romualdo-and-heidis-wishlist/

The good new is it point somewhere but it needs to go to the user's public profile page. What am I missing in the code to redirect it to profile instead of the wishlist page?

The functions.php part where I use query var so that WP catches my custom /user/username url:

add_filter( 'query_vars', 'wpleet_rewrite_add_var' );
function wpleet_rewrite_add_var( $vars )
{
    $vars[] = 'user';
    return $vars;
}

add_rewrite_tag( '%user%', '([^&]+)' );
add_rewrite_rule(
    '^user/([^/]*)/?',
    'index.php?user=$matches[1]',
    'top'
);

add_action( 'template_redirect', 'wpleet_rewrite_catch' );
function wpleet_rewrite_catch()
{
    global $wp_query;

    if ( array_key_exists( 'user', $wp_query->query_vars ) ) {
        include (TEMPLATEPATH . '/UserList.php');
        exit;
    }
}
  • The backend profile page? – s_ha_dum Jan 25 '14 at 15:50
  • no, a custom frontend profile page – user3119567 Jan 25 '14 at 16:01
  • Search the site for 'endpoint' – s_ha_dum Jan 25 '14 at 16:06
  • Then look more closely. Unless you want to create every single /profile/nameOfUser page you need to have your profile page act as an endpoint (or use $_GET parameters). If the endpoint is working creating the link is just the URL to the /profile/ page plus the username. – s_ha_dum Jan 25 '14 at 16:37
  • thanks - will dig a bit deeper - will this 'endpoint' be an automated process if done correctly creating a unique /profile/nameOfUser for each user? – user3119567 Jan 25 '14 at 18:19

Your Answer

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

Browse other questions tagged or ask your own question.