• On the userlist-default.php page, I would like to change the link to the profile page. Currently, it links this way:

    <a href="<?php echo $baselink . urlencode($user['user_login']); ?>"><?php echo $user['display_name']; ?>

    I created a new field (via RegisterPlus plugin) called “headline”. I want to have the headline linked to the user profile page. I tried simply inserting the field name, headline, where display_name is currently, but that did not work. The headline field works on the profile page, so what code do I use to change it from the display_name to the headline field?

    https://www.ads-software.com/extend/plugins/alkivia/

Viewing 5 replies - 1 through 5 (of 5 total)
  • On the profile page, you get all the data associated to the user. The one that comes from both tables: users and usermeta. In the user list only fields from users table are available, so, the field you want to use is not available on the list and you have to retrieve yourself from database.

    You can do it in to ways:

    1) Composing the SQL query to get the field.
    2) With this call: $userdata = get_userdata($user[‘ID’]); and you will have the field on the $userdata object.

    The second option is quicker to code, but more database consumer.

    A suggestion is not to edit the templates supplied, better if you create a new php file from them and use this( You can call the file something like userlist-custom.php, this way is more difficult to lose changes when updating.

    The following post will help you to set the templates outside the plugin folder and never lose your changes when updating (using manual update or auto-update): https://alkivia.org/community/aoc-styling-your-pages/

    Thread Starter temada

    (@temada)

    Thanks Txanny. I appreciate your time.

    I’m an amateur at php, but if you could provide an example of the SQL query and the call within the code at the beginning of the post, that would be extremely helpful. Everything else is working fine.

    If you set more than one field, I would use get_userdata() that way, I would add the lines shown, after line 49, this is the foreach line:

    <?php ( foreach $users as $user ) :
        $userdata = get_userdata($user['ID']);

    Now, you have all data on the $userdata object, so you can display anywhere you want:

    echo $userdata->field_one;
    echo $userdata->field_two;

    For what you want, and if the field name is ‘headline’, you have to change the link line to:

    <td><a href="<?php echo $baselink . urlencode($user['user_login']); ?>"><?php echo $userdata->headline; ?></a></td>

    To get only one field, the code would be:

    global $wpdb;
    $query = "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id='{$user['ID']}' AND meta_key='headline'";
    $headline = $wpdb->get_var($query);

    This have to be placed inside the foreach, and you will get the ‘headline’ field value on the $headline var.

    Code is not tested, but it should work.

    Thread Starter temada

    (@temada)

    Thanks! That worked out nicely.

    I appreciate you taking the time to show me specific examples. I just sent you a donation via PayPal. I look forward to upcoming updates, especially the custom fields feature. Keep up the great work.

    Many thanks! I received the donation, and your help is greatly appreciated. This will help a bit with my hosting costs.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Alkivia Open Community] Change profile link for display name on User list page?’ is closed to new replies.