WordPress.org

Ready to get started?Download WordPress

Forums

Developer's Custom Fields
Echo user fields (4 posts)

  1. Arden012
    Member
    Posted 2 years ago #

    Hi there, I was wondering if you could tell me how to echo the information from user fields. I've added a few extra user fields and I want to display the values of those on the author page and next to posts the author made. Now I just know it must be in your documentation, but I'm just hopeless in figuring it out. Thanks for your time.

    http://wordpress.org/extend/plugins/developers-custom-fields/

  2. Steve Taylor
    Member
    Plugin Author

    Posted 2 years ago #

    You should do something like this:

    <?php $my_user_fields = slt_cf_all_field_values( 'user', $user_id ); ?>

    Where $user_id has been set to the ID of the user you're grabbing the custom fields for. On an author archive template, you can get the ID like this (see http://codex.wordpress.org/Author_Templates#Setting_Up_for_Author_Information):

    <?php
    global $wp_query;
    $curauth = $wp_query->get_queried_object();
    $my_user_fields = slt_cf_all_field_values( 'user', $curauth->ID );
    ?>

    $my_user_fields will then be an array of the values set by fields defined by the Developer's Custom Fields plugin.

    In theory you should be able to do this:

    <?php $my_user_fields = slt_cf_all_field_values( 'user' ); ?>

    However, looking at the code, I've done the default for the user ID wrong - it defaults using wp_get_current_user(), which returns the currently logged in user! For the next version of the plugin, I'll make it so it tries to default to the ID of the author whose archive page is being displayed, and if not it'll default to the ID of the currently logged in user.

    For now, best to get the ID yourself and pass it explicitly.

  3. Arden012
    Member
    Posted 2 years ago #

    Again, thanks for the quick response! Ah that explains why I was seeing my own user information instead of the intended everywhere, haha. If I understand this well, this would make it difficult to create a list with information from all authors, unless I specify the ID for each author independently, right?

  4. Steve Taylor
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, just pass the ID explicitly to slt_cf_field_value or slt_cf_all_field_values - obviously if you're looping through a list of authors, you'll have that ID easily accessible. Not difficult at all :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic