【问题标题】:Saving custom user profile fields to specific table将自定义用户配置文件字段保存到特定表
【发布时间】:2013-02-10 22:52:08
【问题描述】:

我已成功将自定义字段添加到编辑配置文件页面:

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');

但是如何将这些值保存到特定的数据库表中呢?我需要将它们与相应的电子邮件一起保存在另一个表中。我还需要重新加载这些值。任何方向都将不胜感激。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您需要以下 WordPress 类:

    Class Reference/wpdb

    $wpdb 对象可用于从 WordPress 数据库中的任何表中读取数据,而不仅仅是 WordPress 创建的标准表。

    $wpdb 对象可以与任意数量的表对话,但只能与一个数据库对话:WordPress 数据库。在极少数情况下,您需要连接到另一个数据库,您必须使用适当的连接详细信息从 wpdb 类实例化您自己的对象。

    还要检查 Codex 的其他条目:

    Creating Tables with Plugins

    如果您是 WordPress 的writing a plugin,您几乎肯定会发现您需要在 WordPress 数据库中存储一些信息。

    还有一篇关于自定义表格的博客文章:

    Working With Custom Database Tables In WordPress

    如果您已经有一个客户信息数据库,但您希望能够查询该数据并将其显示在 WordPress 模板中,该怎么办?今天我将向您展示如何在 WordPress 引擎中安全地执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多