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

  1. Arden012
    Posted 4 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.


  2. Steve Taylor
    Plugin Author

    Posted 4 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):

    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
    Posted 4 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
    Plugin Author

    Posted 4 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

  • Developer's Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic