WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Developer's Custom Fields] Echo user fields

[Plugin: Developer's Custom Fields] Echo user fields

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Steve Taylor
    Participant

    @gyrus

    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.

    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?

    Plugin Author Steve Taylor
    Participant

    @gyrus

    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 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Developer's Custom Fields] Echo user fields’ is closed to new replies.