【问题标题】:Is it possible to prevent a specific metafield from updating in wordpress?是否可以防止特定元字段在 wordpress 中更新?
【发布时间】:2012-04-21 20:19:10
【问题描述】:

我想阻止 wordpress 保存年、月和日数组。我使用 JavaScript 将隐藏输入中的 3 合为一个值,因此我不需要将 3 存储在数据库中。我该怎么做?

$meta_box = array(
    'id' => 'global-releasedate',
    'title' => 'Releasedate',
    'page' => 'films',
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
            'name' => '',
            'id' => $prefix . 'airdate',
            'type' => 'hidden',
            'std' => ''
        ),

        array(
            'name' => 'Year',
            'id' => $prefix . 'year',
            'type' => 'select',
            'options' => $years,
        ),

         array(
            'name' => 'Month',
            'id' => $prefix . 'month',
            'type' => 'select',
            'options' => $months,
        ),

          array(
            'name' => 'Day',
            'id' => $prefix . 'day',
            'type' => 'select',
            'options' => $days,
        ),
    ));

【问题讨论】:

    标签: php arrays wordpress custom-fields


    【解决方案1】:

    解决方案实际上是删除它们或在functions.php文件中注释它们。如果您删除它们,它们不会从帖子中删除,它们将不再对用户可见,这正是您所需要的。

    【讨论】:

    • 感谢您的回复;但是我想要实现的是将元字段留给新帖子。问题是,我有 3 个选择选项,我使用 JavaScript 在更改时获取它们的值,并将所有 3 个选项存储在一个隐藏输入中的一个组合值中。之后我不需要每个选择选项,因此不会保存它们以保存数据库信息。我想让它存储在数据库中不会是一个坏主意,而不是经历麻烦?
    • 我通过在保存/更新函数周围使用 if 语句找到了解决问题的方法
    猜你喜欢
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多