[英]How to make a sortable admin panel column for a custom field counting the number of page impressions in Wordpress
[英]How to change the value of the input field of custom WordPress admin page?
我制作了一個帶有input fields
的自定義WordPress Admin page
。 我想根據database
在constructor
更改它們的values
。 我不知道如何訪問它們...
在構造函數中調用的函數,它將處理database init
。 數據庫column names
和input 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.