将过滤器添加到 Wordpress 仪表板(不是帖子)

Adding filter to Wordpress dashboard (not posts)

我想在我们公司的项目管理站点的仪表板中筛选列表。我想按用户过滤,但目前 it can only sort by date. The users are displayed on hover so all of the information is there in the table, I just want to add a search bar to filter names. Is this relatively easily done? I am mostly front end so my php skills are somewhat lacking. The plugin being used is Panorma projects.

到目前为止我试过的所有插件都是用于过滤帖子的,它们不会转移到全景页面。

这是在 WP 自定义 Post 类型中添加自定义过滤器的代码。

只需根据您的要求更改代码即可。

在 select 框中的第一个函数中,按角色获取所有用户或特定用户。

并且在第二个函数中使用作者 ID

计算 selected 记录
 function wpse45436_admin_posts_filter_restrict_manage_posts(){
        $type = 'post';
        if (isset($_GET['post_type'])) {
            $type = $_GET['post_type'];
        }

        //only add filter to post type you want
        if ('POST_TYPE' == $type){
            //change this to the list of values you want to show
            //in 'label' => 'value' format
            $values = array(
                'label' => 'value', 
                'label1' => 'value1',
                'label2' => 'value2',
            );
            ?>
            <select name="ADMIN_FILTER_FIELD_VALUE">
            <option value=""><?php _e('Filter By ', 'wose45436'); ?></option>
            <?php
                $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
                foreach ($values as $label => $value) {
                    printf
                        (
                            '<option value="%s"%s>%s</option>',
                            $value,
                            $value == $current_v? ' selected="selected"':'',
                            $label
                        );
                    }
            ?>
            </select>
            <?php
        }
    }


    add_filter( 'parse_query', 'wpse45436_posts_filter' );
    /**
     * if submitted filter by post meta
     * 
     * make sure to change META_KEY to the actual meta key
     * and POST_TYPE to the name of your custom post type
     * @author Ohad Raz
     * @param  (wp_query object) $query
     * 
     * @return Void
     */
    function wpse45436_posts_filter( $query ){
        global $pagenow;
        $type = 'post';
        if (isset($_GET['post_type'])) {
            $type = $_GET['post_type'];
        }
        if ( 'POST_TYPE' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') {
            $query->query_vars['author'] = ID of the user from $_GET;
        }
    }