php - 将表单值保存在 WordPress 的 post_meta 中

标签 php mysql wordpress

function yummy_sounds_custom(){
    add_menu_page( 
        __( 'Custom Menu Title', 'textdomain' ),
        'Licence',
        'manage_options',
        'licence',
        'licence_fields',
        '',
        6
    ); 
}

add_action( 'admin_menu', 'yummy_sounds_custom' );



/**

 * Display a custom menu page

 */
function licence_fields() {
    ?>
    <h2>Fill the licence details</h2>

    <form method="post" action="">
    <div>Licence Title :</br> <input type="text" name="title" /></div>
    <div>Licence Tagline :</br> <input type="text" name="tagline" /></div>
    <div>Price :</br> <input type="text" name="price" /></div>
    <div>Currency Symbol :</br> <input type="text" name="symbol" /></div>
    <div>Description :</br> <textarea rows="7" cols="50" name="description"></textarea></div>
    <div><input type="submit" value="Submit" name="submit"></div>
    </form>

我是 WordPress 自定义新手,所以我不知道如何在 WordPress 表中保存数据。我正在自定义管理菜单中创建此表单,并希望在 post_meta 中保存数据,我如何才能做到这一点?

提前致谢

最佳答案

您可以为此使用 Wordpress Ajax 功能:Wordpress Codex

使用update_option保存数据并使用get_option函数读取数据。这是单一许可证的场景。

如果您想创建许可证集合,就像帖子一样,您必须创建新的 custom post type 。然后您将在新帖子类型中获得帖子 ID,并且您可以使用 update_post_metaget_post_meta

关于php - 将表单值保存在 WordPress 的 post_meta 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45477039/

相关文章:

MYSQL group_concat 与 IF

phpmyadmin - MYSQL 查询来计算 mysql 服务器中存在的模式数量

php - 有没有一个好的库可以用 php 分割一个 mp3

php - 使用 MySql php 计算循环字段

php - 表单帖子和 jquery 帖子之间的区别

html - CSS Bug : Footer under images on Firefox, 但在其他 Web 浏览器上位于图像之上

php - mPdf 中的图像未在服务器中显示,但在本地主机中运行良好

javascript - 无法为每个输入字段提交右键[单个表单中的多个按钮和输入字段]

mysql - mysql 代码遇到问题,不断出现错误 1064

php - 文件已从一个域上传到另一个域,但菜单不起作用