简体   繁体   English

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

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

I made a custom WordPress Admin page with input fields .我制作了一个带有input fields的自定义WordPress Admin page I would like to change the values of them in the constructor based on the database .我想根据databaseconstructor更改它们的values I have no idea how to access them...我不知道如何访问它们...

The function which is called in the constructor and which will handle the database init .在构造函数中调用的函数,它将处理database init The database column names and input field ids are the same:数据库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 : 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']);
    }
}

So I need to somehow access the fields outside the function.所以我需要以某种方式访问​​函数之外的字段。

The registered settings are stored in wordpress wp_options table by uid, you can access them using theget_option function.注册的设置通过 uid 存储在 wordpress wp_options 表中,您可以使用get_option函数访问它们。 As your column name is same as your uid u can get the value of the field by get_option($column).由于您的列名与您的 uid 相同,因此您可以通过 get_option($column) 获取该字段的值。 You can update the values using update_option ($column, $new_value).您可以使用update_option ($column, $new_value) 更新值。

暂无
暂无

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

相关问题 如何为自定义字段创建可排序的管理面板列,以计算Wordpress中的页面印象数 - How to make a sortable admin panel column for a custom field counting the number of page impressions in Wordpress Wordpress:基于自定义字段值更改图像 - Wordpress: Change Image based on custom field value 自定义字段未显示在管理 Wordpress 中 - Custom field not showing in admin Wordpress 在 Woocommerce 管理页面中设置默认的自定义计费 state 字段值 - Set a default custom billing state field value in Woocommerce Admin page 如何在Wordpress中按自定义字段值排序帖子 - How to order posts by custom field value in wordpress 如何在WordPress管理页面的用户列表中添加自定义where条件? - How to add custom where condition in user listing at WordPress admin page? 如何在 wp-admin wordpress 的项目页面中更改标签? - How to change labels in the projects page in wp-admin wordpress? 如何从页面正文中的自定义字段获取值,然后将其放在标题的meta标签内容中? WordPress的 - How can I get value from a custom field in body of a page, then put it in the meta tags content in header? Wordpress 寻找了解自定义字段如何更改wordpress网站的functions.php中的值 - Looking to learn how a Custom Field can change a value in the functions.php of a wordpress site 如果自定义字段值存在,如何从默认值全局更改Wordpress默认排序顺序 - How to globally change Wordpress default sorting order from default if custom field value exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM