Saving custom user profile fields to specific table

I’ve successfully added custom fields to the edit-profile page:

function directoryFields() { ?>

    <h3>Directory Info</h3>

    <table class="form-table">

        <tr>
            <th><label for="responsibilities">Primary work responsibilities</label></th>
            <td><textarea name="responsibilities" id="responsibilities" rows="5" cols="30">Load info here...</textarea><br />
        </tr>
        <tr>
            <th><label for="ask">Ask me about</label></th>
            <td><textarea name="ask" id="ask" rows="5" cols="30">Load info here...</textarea><br />
        </tr>
        <tr>
            <th><label for="ask">Memberships and Affiliations</label></th>
            <td><textarea name="memberships" id="memberships" rows="5" cols="30">Load info here...</textarea><br />
        </tr>
        <tr>
            <th><label for="ask">Education</label></th>
            <td><textarea name="education" id="education" rows="5" cols="30">Load info here...</textarea><br />
        </tr>

    </table>

<?php }

add_action('show_user_profile', 'directoryFields');

But how does one go about saving these values to a specific database table? I need to save them with the according email, in another table. I will also need to load the values back in. Any direction would be greatly appreciated.

Related posts

Leave a Reply

1 comment

  1. You’ll need the following WordPress class:

    Class Reference/wpdb

    The $wpdb object can be used to read data from any table in the WordPress database, not just the standard tables that WordPress creates.

    The $wpdb object can talk to any number of tables, but only one database: the WordPress database. In the rare case you need to connect to another database, you will have to instantiate your own object from the wpdb class with the appropriate connection details.

    Check also this other entry of the Codex:

    Creating Tables with Plugins

    If you are writing a plugin for WordPress, you will almost certainly find that you need to store some information in the WordPress database.

    And a blog article about Custom Tables:

    Working With Custom Database Tables In WordPress

    What if you already have a database of say, customer information, but you want to be able to query that data and display it within a WordPress template? Today I’ll be showing you just how to do that, safely within the WordPress engine.