'Wordpress custom admin page - Save Checkbox

I am trying to create a custom page in the administration panel to save some checkboxes somewhere in an array so that later I can show them in the wordpress theme. But the truth is I am limited, I do not know how to continue to save that information, nor do I know if it is better to use update_option () or update_post_meta () to save that configuration. I have the following code in the theme's functions file:

function wpdocs_unsub_add_pages() {
     add_menu_page(
        __( 'Unsub List', 'textdomain' ),
        __( 'Unsub Emails','textdomain' ),
        'manage_options',
        'categoriasrelacionadas',
        'wpdocs_unsub_page_callback',
        ''
    );
}
 
/**
 * Display callback for the Unsub page.
 */
function wpdocs_unsub_page_callback() {
     echo 'Unsubscribe Email List';
?>
          
<form method="post" 
      action="<?php echo esc_html('?page=categoriasrelacionadas'); ?>">

    <?php $cat_argtos=array(
       'orderby' => 'name',
       'order' => 'ASC');

    $categorias=get_categories($cat_argtos);
    foreach($categorias as $categoria) {
        $args=array(
            'showposts' => -1,
             'category__in' => array($categoria->term_id),
             'caller_get_posts'=>1
        );
        $entradas=get_posts($args);
        if ($entradas) {
            echo '<p>' .$categoria->name.
            '<input type="checkbox" 
                    name="categorias" 
                    value="'.$categoria->term_id.'">  
             </p>';
        }
    }
    ?>
    <?php
        wp_nonce_field( 'acme-settings-save', 'acme-custom-message' );
        submit_button();
    ?>
</form>
<?php 
...
}

What else could I do to save the information and show the selected boxes?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source