• I’m a relative PHP newbie, so this is probably easy (but driving me nuts…)

    I’ve installed the WP User Manager plugin, to get extra fields for users. I’ve added an ‘address’ field, and I want to display the contents of ‘address’ on every post (next to the author’s name.)

    I’m able to get it to work if I hard-code the user ID, just to test it. For example, if I include this code in my single post template:

    $meta_key = ‘wpum_’.'address’;
    $meta_data = get_usermeta(4,$meta_key);
    echo $meta_data;

    I get the address diplayed for user ID 4. (Ex: 123 Mockingbird Lane) Obviously, though I don’t want to hard code a user ID, I want the user ID of the post author.

    I’ve tried everything I can think of to use the_author_ID() instead of the hard coded ID, but no matter what I try, all that’s output is the actual ID (in this case “4”), instead of the address.

    I’ve tried:

    $meta_data = get_usermeta(the_author_ID(),$meta_key); (with quotes around the_author_ID(), without quotes, with and without semi-colons, etc.)

    I’ve also tried assigning the_author_ID() to a variable first.
    $meta_id = the_author_ID();
    I’ve tried using intval. For the life of me I can’t figure out how to get the get_usermeta function to work with the_author_ID() instead of a hard-coded number. Everything I try only outputs the number 4.

    Any idea? Thanks…

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tcervo

    (@tcervo)

    bump

    Thread Starter tcervo

    (@tcervo)

    Anybody?

    Thread Starter tcervo

    (@tcervo)

    bump

    Try…

    get_the_author_ID()

    instead of…

    the_author_ID()

    indeed the
    get_the_author_ID();

    will do the job. you might want to have a look also to the
    get_currentuserinfo(); function

    <?php
          get_currentuserinfo();
          echo('Username: ' . $userdata->user_login . "\n");
          echo('user_ md5: '. $userdata->user_pass . "\n");
          echo('User level: ' . $userdata->user_level . "\n");
          echo('User ID: ' . $userdata->ID . "\n");
    ?>

    for what concerns the address part i’m not sure as i’m also struggling to get extra user info from a different plugin…

    you can try to use this form and see if you get anything out:

    if( get_user_option($option_name, $yourVarField) ):
    echo get_user_option($option_name, $yourVarField);
    endif;

    yourVarField is the name of the field as it is in the registration/database

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_usermeta question’ is closed to new replies.