I have a custom post type and I’d like to save somewhere the latest update… I thought about creating a field under Settings and just update its value when the update is complete and then display that value using an admin notification inside of my custom post type back-end page.
Or maybe, add a custom field to the post type page (not the item) and just update and display it, not sure if it is possible.
This is what I have for the settings page:
add_action('admin_init', 'my_general_section');
function my_general_section() {
add_settings_section(
'inventory_update_date', // Section ID
'Inventory Update', // Section Title
'my_section_options_callback', // Callback
'general' // What Page? This makes the section show up on the General Settings Page
);
add_settings_field( // Option 1
'inventory_update', // Option ID
'Inventory Update', // Label
'my_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'inventory_update_date', // Name of our section
array( // The $args
'inventory_update' // Should match Option ID
)
);
register_setting('general','option_1', 'esc_attr');
}
function my_section_options_callback() { //section description
echo '';
}
function my_textbox_callback($args) { // Textbox Callback
$option = get_option($args[0]);
echo '<input type="text" id="'. $args[0] .'" name="'. $args[0] .'" value="' . $option . '" />';
}This code displays a custom section/field on this page /wp-admin/options-general.php but it doesn’t save its value, what am I missing? Any better idea? Tks!
