繁体   English   中英

如何更改自定义 WordPress 管理页面的输入字段的值?

[英]How to change the value of the input field of custom WordPress admin page?

我制作了一个带有input fields的自定义WordPress Admin page 我想根据databaseconstructor更改它们的values 我不知道如何访问它们...

在构造函数中调用的函数,它将处理database init 数据库column namesinput field ids相同:

public function update_inputs(){
    global $wpdb;
    $columns = $wpdb->get_col("DESC `dbtable-admin`", 0);
    foreach($columns as $column){
        /*if($column == field name){
            field name.value = $wpdb -> get_var("SELECT $column FROM `dbtable-admin`");
        }*/
    }
}

Field setup

public function setup_fields()
{
    $fields = array(
        array(
            'uid' => 'page_name',
            'label' => 'Oldal neve',
            'section' => 'custom_page_settings',
            'type' => 'text',
        ) ,
        //Others are the same.
     );
     foreach ($fields as $field)
    {

        add_settings_field($field['uid'], $field['label'], array(
            $this,
            'field_callback'
        ) , 'custom-main-menu', $field['section'], $field);
        register_setting('custom-main-menu', $field['uid']);
    }
}

所以我需要以某种方式访问​​函数之外的字段。

注册的设置通过 uid 存储在 wordpress wp_options 表中,您可以使用get_option函数访问它们。 由于您的列名与您的 uid 相同,因此您可以通过 get_option($column) 获取该字段的值。 您可以使用update_option ($column, $new_value) 更新值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM