【问题标题】:Wordpress plugin options pageWordpress 插件选项页面
【发布时间】:2014-05-07 14:29:14
【问题描述】:

我正在尝试创建一个 wordpress twitter 插件,对于我的选项页面,我需要将表单保存到我设法创建的表中。我已经创建了表格,现在我需要知道如何确保它发布到我的表格中?我有以下代码,我的表名是 wp_twitter_carla。

function register_mysettings() {
    //register our settings
    register_setting( 'twitter-settings-group', 'twitteruser' );
    register_setting( 'twitter-settings-group', 'notweets' );
    register_setting( 'twitter-settings-group', 'replies' );
    register_setting( 'twitter-settings-group', 'retweets' );
}

function twitter_settings_page() {
?>
<div class="wrap">
<h2>Twitter Feed by Carla</h2>

<form method="post" action="options.php">
    <?php settings_fields( 'twitter-settings-group' ); ?>
    <?php do_settings_sections( 'twitter-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Twitter Username</th>
        <td><input type="text" name="twitteruser" value="<?php echo get_option('twitteruser'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Number of tweets to show</th>
        <td><input type="text" name="notweets" value="<?php echo get_option('notweets'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Show replies?</th>
        <td><input type="text" name="replies" value="<?php echo get_option('replies'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Show retweets?</th>
        <td><input type="text" name="retweets" value="<?php echo get_option('retweets'); ?>" /></td>
        </tr>
    </table>

    <?php submit_button(); ?>

</form>
</div>

【问题讨论】:

  • 当您注册一个设置时,它会转到表wp_options。您不需要自己的表格来仅保存这 4 个选项...我认为您的意图是将实际的推文保存在表格中,不是吗?

标签: php wordpress


【解决方案1】:

Wordpress 应该将您的设置保存在 wp_options 表中。打开 phpmyadmin,选择你的数据库并点击 sql 把这段sql代码写在那里

SELECT * FROM `wp_options` WHERE `option_name` LIKE '%twitter-settings-group%' OR `option_value` LIKE '%twitter-settings-group%

wp 应该有一个结果是序列化您的表单并在数据库中保留一行。

最好的问候, 吊艇架。

【讨论】:

    【解决方案2】:

    虽然这不能直接回答您的具体问题,但我建议您使用Redux Framework。它是一个基于 WordPress 设置 API 构建的选项框架,非常易于使用。它将为您处理所有的数据库发布、检索等。花一些时间学习他们的 API 绝对值得,我想你会很高兴的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 2022-01-02
      相关资源
      最近更新 更多