logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$15
How to display user meta in profile page?

Hello,

I am using the gravity forms user registration plugin.

This plugin is generating custom user meta.

This is how my meta strings appear in gravity forms...

* Title
* Publication / Company
* Job Title
* Publication Location
* Language

But how do you find out what the meta key is for these?

And how do you get them to display in the user profile page?


Many Thanks
Josh


This question has been answered.

Josh Cranwell | 01/26/12 at 7:12pm Edit

Previous versions of this question: 01/26/12 at 7:13pm

The experts have suggested, on average, a prize of $35 for this question.

(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/26/12
    7:18pm
    Fahd Murtaza says:

    Hi Josh

    (prefix)_usermeta is the wordpress MySQL table which you need to look into.

    The keys are all saved there.

    Then simply use this function for profile.


    <?php
    $user_id = 9; // which you can get dynamically
    $key = 'last_name'; // last_name be replaced by your own key which you got from the MySQL table
    $single = true;
    $user_last = get_user_meta( $user_id, $key, $single );
    echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>';
    ?>


    I hope it gets you started, please ask for more help after trying these.

    Previous versions of this answer: 01/26/12 at 7:18pm

    • 01/26/12 7:20pm

      Fahd Murtaza says:

      One question, do you want them on front end in the theme i.e user profile page on front end of the site?

    • 01/26/12 7:21pm

      Josh Cranwell says:

      I thought that maybe the case - I don't have access to MySQL table. Can it be seen anywhere from admin?

    • 01/26/12 7:22pm

      Fahd Murtaza says:

      Yes it can be seen from admin. Just give me wp-admin access.

    • 01/26/12 7:23pm

      Josh Cranwell says:

      Both.

      I would like them to be in the back end user profile page.

      But also on my front end user profile page.

    • 01/26/12 7:25pm

      Josh Cranwell says:

      I'm really interested to know how to find out the meta?

      Do you mind hinting on how I can do this and I might be able to work the rest out thanks.

    • 01/26/12 7:31pm

      Fahd Murtaza says:

      I need to know the exact names of keys in the SQL table I mentioned. I can get it through wp-admin only. The reason being, I am not sure how the Gravity forms save data or else I would have known without even looking into DB.

      About meta, I already provided you code in which you will just need to replace certain information as documented in the comments.

    • 01/26/12 7:34pm

      Fahd Murtaza says:

      OK Josh

      See what Francisco says. His and mine solutions can work together. For looking into db keys just use that.

  • avatar
    Last edited:
    01/26/12
    7:26pm
    Francisco Javier Carazo Gil says:

    Hi Josh,

    You can use the author.php into Twenty Ten as a guide. As you can see, in author page you can use this function: get_the_author_meta.

    The use is simple:
    * get_the_author_meta('language');
    * Or if you want to get the value into screen with an echo: the_author_meta('language');

    • 01/26/12 7:30pm

      Francisco Javier Carazo Gil says:

      To see the meta keys that Gravity Forms use, directly with a file of your template do the next:


      $authors_meta = $wpdb->get_results(
      "
      SELECT umeta_id, user_id, meta_key, meta_value
      FROM $wpdb->usermeta;
      "
      );

      foreach ( $authors_meta as $author_meta )
      {
      echo $author_meta->meta_key . " - " . $author_meta->meta_value . "<br/">;
      }

    • 01/26/12 7:41pm

      Josh Cranwell says:

      Sorry Francisco

      Your going to have to bear with me, where do I put this?

      Will this make that data appear in my control panel user profile page?

      I'm not very good when it comes to this part of wordpress :/

  • avatar
    Last edited:
    01/26/12
    7:27pm
    John Cotton says:

    If you're happy with the info appearing in text boxes under contact info on the dashboard profile, then this will do it:


    function my_user_contactmethods($user_contactmethods) {
    // You can get rid of ones you don't want
    unset($user_contactmethods['jabber']);
    unset($user_contactmethods['yim']);
    unset($user_contactmethods['aim']);

    // And add any news ones. The array key is the meta key name, the text
    // is however you want it labelled.
    $user_contactmethods['skype'] = __('Skype');

    return $user_contactmethods;
    }
    add_filter( 'user_contactmethods', 'my_user_contactmethods');


    It's possible to do a more customised presentation of user meta on the profile page, but it's more complicated. The code above may well suffice.

    • 01/26/12 7:31pm

      Josh Cranwell says:

      Ok thats, cool but how do you find out the custom meta prefix's?

      Gravity forms has generated my custom user meta, but I don't know what the prefix's are.

      The problem is I've tried so many user registration plugins, and finally found the winning plugin...

      but for all I know I could be on custom_usermeta_24 by now.

    • 01/26/12 7:34pm

      John Cotton says:

      Stick this code somewhere you can see the output:

      $meta = get_user_meta($user_id); print_r($meta);


      You can get a user id by looking at the url in the dashboard profile page.

      The code above will output all the meta data for the user and you will be able to see what each is called.

    • 01/26/12 7:39pm

      Josh Cranwell says:

      Sorry I'm very tired and I not php savy

      So your saying if I put this anywhere in my theme so I can see an output, this will show the current logged in user meta data?

      <?php $meta = get_user_meta($user_id); print_r($meta); ?>

    • 01/26/12 7:42pm

      John Cotton says:

      This

      <?php $user_id = 7; $meta = get_user_meta($user_id); print_r($meta); ?>


      will show you the user meta of which ever user you set $user_id to.

      This

      <?php global $current_use; $meta = get_user_meta($current_user->ID); print_r($meta); ?>

      will show the current logged in user meta data.

      Stick the code at the end of you header.php file and it will appear at the top of your page.

    • 01/26/12 7:48pm

      Josh Cranwell says:

      Array ( [Job Title] => Array ( [0] => Designer ) [Publication Location] => Array ( [0] => United Kingdom ) [authentication] => Array ( [0] => 1 ) [Title] => Array ( [0] => Mr ) [Publication / Company] => Array ( [0] => Motocom Digital ) [entry_id] => Array ( [0] => 5 ) [wp_user_level] => Array ( [0] => 0 ) [show_admin_bar_front] => Array ( [0] => true ) [wp_capabilities] => Array ( [0] => a:1:{s:5:"media";s:1:"1";} ) [use_ssl] => Array ( [0] => 0 ) [rich_editing] => Array ( [0] => true ) [comment_shortcuts] => Array ( [0] => false ) [description] => Array ( [0] => ) [last_name] => Array ( [0] => Cranwell ) [nickname] => Array ( [0] => motocomdigital@gmail.com ) [first_name] => Array ( [0] => Josh ) [Language] => Array ( [0] => English ) [admin_color] => Array ( [0] => fresh ) ) 


      This what has outputted. So are my meta keys exactly the same as the name of the my field?

      Array ( 
      [Job Title] => Array ( [0] => Designer )
      [Publication Location] => Array ( [0] => United Kingdom )
      [authentication] => Array ( [0] => 1 )
      [Title] => Array ( [0] => Mr )
      [Publication / Company] => Array ( [0] => Motocom Digital )


      So is how would I get this to display admin user profile page? And be able to edit it?

      Is it a lengthy process?

      Thanks

    • 01/26/12 7:50pm

      Josh Cranwell says:

      So is how would I get this to display admin user profile page? And be able to edit it?


      I meant...

      How would I get this to display admin user profile page? And be able to edit, like you can with other profile information?

    • 01/26/12 7:52pm

      John Cotton says:

      Stick this in you functions.php file:



      function my_user_contactmethods($user_contactmethods) {
      // You can get rid of ones you don't want
      unset($user_contactmethods['jabber']);
      unset($user_contactmethods['yim']);
      unset($user_contactmethods['aim']);

      // And add any news ones. The array key is the meta key name, the text
      // is however you want it labelled.
      $user_contactmethods['Job Title'] = __('Job Title');
      $user_contactmethods['Publication Location'] = __('Publication Location');
      $user_contactmethods['Title'] = __('Title');
      // etc for each field you want to appear

      return $user_contactmethods;
      }
      add_filter( 'user_contactmethods', 'my_user_contactmethods');

    • 01/26/12 7:57pm

      Josh Cranwell says:

      A gentleman and a scholar, thank you!!!!!!!!!!

      Worked a treat.

      Cheers John

    • 01/26/12 7:58pm

      John Cotton says:

      My pleasure!

      I see that this question you asked:
      http://wpquestions.com/question/showLoggedIn/id/3433

      Was never voted on. Any reason?

    • 01/26/12 8:06pm

      Josh Cranwell says:

      If I'm honest John, I can't really remember.

      I can't even see I've replied on there, so must have expired early.

      I'm a graphic designer doing a developers job, and I think I get caught up in the thick of it at times, sorry I let that one go.

This question has expired.



Gabriel Reguly, Hai Bui, Christianto, Josh Cranwell, Julio Potier, Kannan C, Francisco Javier Carazo Gil voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.