$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - Options page - dropdown of users|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - Options page - dropdown of users

matteradmin11PV0评论

I want to create an options page in WPAdmin that will let me select among registered post type "Members" and anoint them as "captains". Here is my code so far but the dropdown is not functioning correctly.

Any help much appreciated!

/* Admin Captains
––––––––––––––––––––––––––––––––––––––––––––––––––*/


// Create the menu

add_action( 'admin_menu', 'my_admin_captains' );

function my_admin_captains() {
    // Add the sub-menu to Users
    add_submenu_page( 'users.php', 'My Admin Captain Options', 'My Admin Captains', 'manage_options', 'admin_captains_options', 'my_admin_captains_options');
    // Call the register settings function
    add_action( 'admin_init', 'register_my_admin_captains_options' );
}

function register_my_admin_captains_options() {
    //register our settings
    register_setting( 'my_admin_captains_options_group', 'admin_captain_projects' );
    register_setting( 'my_admin_captains_options_group', 'admin_captain_people' );
}


// Create the page

function my_admin_captains_options() {
    if ( !current_user_can( 'manage_options' ) )  {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    }

    ?>


    <div class="wrap">
        <h1>Admin Captains</h1>
        <p>This page assigns users as "Admin Captains", showcasing them on the home page as people responsible for particular areas of I/O.</p>

        <form method="post" action="options.php">

            <?php settings_fields( 'my_admin_captains_options_group' ); ?>
            <?php do_settings_sections( 'my_admin_captains_options_group' ); ?>

            <h4>Projects &amp; Documents Captain</h4>


            <?php
                $teamMembers = get_posts( array(
                            'post_type'      => 'members',
                            'posts_per_page' => -1
                            )
                            );
                $ac_projects = esc_attr( get_option('admin_captain_projects') );
                $ac_projects = explode(",", $ac_projects);  

                echo '<select class="chosen" name="admin_captain_projects[]"  style="width:300px;">';
                echo '<option value="0"></option>';
                foreach ($teamMembers as $p) {
                    $selected ="";
                    if (in_array($p->ID, $ac_projects)) {
                        $selected = ' selected="selected" ';
                     }
                    // echo '<option'.$selected.' value="'.$p->ID .'">'. $p->post_title   .'</option>';


                }
                echo '</select>';







            ?>



            <?php submit_button(); ?>
        </form>





    </div>

<?php
}
Post a comment

comment list (0)

  1. No comments so far