将自定义组合框过滤器添加到Wordpress中的管理员用户列表

时间:2011-09-28 12:00:05

标签: wordpress list filter

我想在管理员用户列表面板中添加2个组合框。例如,第一个将是一个包含国家/地区的组合框,另一个组合将是“用户年龄”。 所以我想添加这些组合以过滤用户列表。

请你在这里说清楚一点?。

谢谢。

2 个答案:

答案 0 :(得分:2)

这就是我要找的:

add_action('restrict_manage_posts','my_restrict_manage_posts');

        function my_restrict_manage_posts() {
            global $typenow;

            if ($typenow=='your_custom_post_type'){
                         $args = array(
                             'show_option_all' => "Show All Categories",
                             'taxonomy'        => 'your_custom_taxonomy',
                             'name'               => 'your_custom_taxonomy'

                         );
                wp_dropdown_categories($args);
                        }
        }
add_action( 'request', 'my_request' );

function my_request($request) {
    if (is_admin() && $GLOBALS['PHP_SELF'] == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type']=='your_custom_post_type') {
        $request['term'] = get_term($request['your_custom_taxonomy'],'your_custom_taxonomy')->name;
    }
    return $request;
}

答案 1 :(得分:0)

您可以将自己的字段添加到用户添加/编辑字段 此示例显示如何添加地址输入字段,如果您正常工作,请尝试使用您需要的下拉列表进行切换。如果这就是'combobox'的意思

function fb_add_custom_user_profile_fields( $user ) {
?>
    <h3><?php _e('Extra Profile Information', 'your_textdomain'); ?></h3>
    <table class="form-table">
    <tr>
    <th>
    <label for="address"><?php _e('Address', 'your_textdomain'); ?>
    </label></th>
    <td>
    <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e('Please enter your address.', 'your_textdomain'); ?></span>
    </td>
    </tr>
    </table>
    <?php }
    function fb_save_custom_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
    return FALSE;
    update_usermeta( $user_id, 'address', $_POST['address'] );
    }
    add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
    add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
    add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );