plugins – Save select setting in wordpress settings page
Question
I want to save cpt name in setting’s page options. I have the cpt list in select dropdown. I am not sure how to save the selected option.
Below is the code that displays the cpt list. Can anyone guide me? how do I save the selected option?
function ctp_settings_page()
{
add_settings_section("section", null, null, "cpt");
add_settings_field("cpt-select", "Select CPT", "cpt_checkbox_display", "cpt", "section");
register_setting("section", "cpt-select");
}
function cpt_checkbox_display()
{
?>
<?php
$post_types = get_post_types(array('public' => true, '_builtin' => false ), 'names', 'and');
?>
<select class="" name="cpt-select">
<?php
foreach ($post_types as $post_type) {
?>
<option value="<?php echo esc_attr($post_type); ?>"><?php echo esc_html($post_type); ?></option>
<?php
}
?>
</select>
<?php
}
add_action("admin_init", "ctp_settings_page");
0
2 months
2022-12-08T08:41:26-05:00
2022-12-08T08:41:26-05:00 0 Answers
0 views
0
Leave an answer