Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Edit Account – read and write to MySQL

User meta information, like that on the profile page, is stored in the usermeta table in the database. You can add extra fields by hooking into the show_user_profile and edit_user_profile action hooks. Then you can save the information by hooking into the personal_options_update and edit_user_profile_update action hooks with a function that updates the new field in the user meta table, update_user_meta().

First create the fields to be rendered on the profile page

//display extra profile fields
add_action( 'show_user_profile', 'extra_profile_fields' );
add_action( 'edit_user_profile', 'extra_profile_fields' );

function extra_profile_fields( $user )
{
    ?>
        <h3>Extra Profile Fields</h3>

        <table class="form-table">
            <tr>
                <th><label for="UID-Nummer"><?php _e( 'UID-Nummer', 'woocommerce' ); ?></label></th>
                <td><input type="text" name="uid-nummer" value="<?php echo esc_attr( get_the_author_meta( 'uid-nummer', $user->ID ) ); ?>" class="regular-text" /></td>
            </tr>
        </table>
    <?php
}

Note the name attribute. It’s a good idea to use this same name when saving the field. You can see that we are pulling that field into the value already using get_the_author_meta( 'uid-nummer', $user->ID ).

Save the fields

//save extra profile fields
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );

function save_extra_profile_fields( $user_id )
{
    update_user_meta( $user_id,'uid-nummer', sanitize_text_field( $_POST['uid-nummer'] ) );
}

Using the fields

To display the field ui-nummer you can use either:

//return the author meta
get_the_author_meta( 'ui-nummer', $user->ID );

or

//echo the author meta
the_author_meta( 'ui-nummer', $user->ID );

Related Posts:

  1. How to check if a meta value has already been assigned to any user?
  2. How can I save unique user data on my site? [closed]
  3. How to store checkbox data for individual users?
  4. Usermeta data unserialize, extract and display in table in WordPress
  5. How can get all users by current user meta (array)?
  6. Let users register weight each day and save it in DB
  7. Large Woocommerce Site (83,000 items), What Can I Do? [closed]
  8. $wpdb->insert() does not Insert record in a table
  9. Using custom tables for old posts
  10. Help with a $wpdb MySQL Query
  11. WordPress SQL injection
  12. Not connecting to database in file with multiple MySQL connections
  13. Way to bulk make all my tags lowercase?
  14. $Wpdb post meta query is not working with mutliple meta keys and values? [closed]
  15. How i can obtain all the post meta for a specific post as an array?
  16. multiple where condition in result query
  17. a:0:{} is replaced into database as s:6:”a:0:{}”;
  18. Grouping posts by a custom meta value
  19. Multiple meta_key in one global $wpdb;
  20. Custom array from a query only write the last row of the query
  21. WordPress member notification
  22. Read array in php?
  23. Can’t Query Custom Table Using $wpdb Method
  24. Moving wordpress site from localhost to live server using GoDaddy cPanel
  25. How does WP work in conjunction with a web server?
  26. WordPress Block developer from exporting Database via PHP
  27. $wpdb returns duplicate posts
  28. Update postmeta after theme switch
  29. Mixing variables into an array when inserting values
  30. Location of core code for database connection and get_header
  31. wpdb prepare insert table doesn’t work
  32. Should I use WordPress to skin a database website?
  33. php include not working in custom page
  34. How do I display offsite database info on my wordpress site?
  35. Creating Database Table vs. Adding MetaData to Post & User
  36. Countdown to date function?
  37. Make a database query using WordPress
  38. Force Users To Relogin
  39. WordPress and MySQL: trying to print data using PHP from user_meta custom field data
  40. WordPress Custom SQL Table with UserID Filter for results
  41. how to prevent wordpress admin from logging in via woocommerce my-account page
  42. Getting users with a specific meta data and then querying their posts?
  43. How to update and save user metadata on page visits?
  44. Most commented posts by time period (last 12h, last 24h and etc)
  45. Use $wpdb or other PHP script method to find/replace in WP database
  46. email alert for product availability
  47. How can I add a new row in a separate database when someone registers via WordPress?
  48. Shortcode to embed Edit Account form not working
  49. Issue with fetching mysql data and displaying results via shortcode in webpage
  50. Login redirect. Check user meta and redirect accordingly
  51. Basic wpdb update question
  52. If Array Values Match Another Array’s Values, Then
  53. Hide posts if user is added to it WP_query
  54. User Meta Value not echoing despite Var_Dump Showing correct string
  55. Shortcode for Listing Users from Meta Value?
  56. I can’t update my data through $wpdb
  57. A $_POST should occur when submit form but is not?
  58. Custom route and query
  59. Output: “Array”
  60. One account with multiple logins
  61. Getting different user data depending on where I use variable
  62. How to unserialize data from MySQL
  63. How to use mysql LIKE with wpdb?
  64. Adding Author Box Meta Links with Co-Authors
  65. Pull MySQL data from multiple tables and merge into 1 PHP array
  66. Get the users that my following users are following
  67. Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
  68. WordPress WP_Query without query GET parameters
  69. How do I prepare strings for insertions as values into a MySQL table?
  70. Known Issues in WordPress When Upgrading PHP to ver 7
  71. Comapare get_user_meta value
  72. How can get all users by current user meta?
  73. Using CFDB7 vs Custom MySQL Database [closed]
  74. How to use AJAX in WordPress in MYSQL query?
  75. add category to posts with tag wordpress
  76. How can I Use 2 databases with one WordPress install
  77. Use variable in SQL statement
  78. Using wordpress function to retrieve data
  79. Live search from database table
  80. Processing ajax call to php to insert into mysql database
  81. form $_post action value gets truncated after it passes through two forms
  82. Get the id of the row from database on click of a button [closed]
  83. Why won’t this wpdb get_results query return results?
  84. WPDB secure custom form
  85. Why when I create a new post I found 2 record related to this post into the posts database table?
  86. Adding data to custom wordpress database table
  87. mySQL queries are executed twice on wordpress website
  88. phpMyAdmin error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
  89. Add row to custom database Table and delete all rows older than 1 day
  90. select a single val though a table in wordpress
  91. making php value numeric
  92. populate select options from extra mysql table data
  93. Query the links Database
  94. Most viewed posts in WordPress
  95. How to create Loop code for Menu using WordPress?
  96. Uses for function: wp_update_user
  97. WordPress Custom Query: Combining Two Functions
  98. Removal of all posts content in bulk, keeping the posts itself
  99. SQL error with custom query
  100. Update user repeater meta (ACF) with another user meta field value
Categories PHP Tags account, mysql, php, user-meta
How to use the ‘Quick edit’ option only for Admin and Editor in ‘All posts’ on the Dashboard?
wp_remote instead of file_get_contents on non json

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress