Php 将筛选器添加到Wordpress仪表板(非POST)

Php 将筛选器添加到Wordpress仪表板(非POST),php,wordpress,plugins,filter,dashboard,Php,Wordpress,Plugins,Filter,Dashboard,我想在我们公司的项目管理网站的仪表板中筛选一个列表。我想按用户进行筛选,但目前没有。用户显示在hover上,所以所有信息都在表中,我只想添加一个搜索栏来过滤名称。这样做相对容易吗?我主要是前端,所以我的php技能有些欠缺。正在使用的插件是 到目前为止,我尝试的所有插件都是用于过滤帖子的,它们不会带到全景页面。这是在WP自定义帖子类型中添加自定义过滤器的代码 只需根据您的需求更改代码 在选择框的第一个函数中,按角色获取所有用户或特定用户 在第二个函数中,使用作者ID编辑所选记录 function

我想在我们公司的项目管理网站的仪表板中筛选一个列表。我想按用户进行筛选,但目前没有。用户显示在hover上,所以所有信息都在表中,我只想添加一个搜索栏来过滤名称。这样做相对容易吗?我主要是前端,所以我的php技能有些欠缺。正在使用的插件是


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

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

只需根据您的需求更改代码

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

在第二个函数中,使用作者ID编辑所选记录

 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;
        }
    }
函数wpse45436_admin_posts_filter_restrict_manage_posts(){
$type='post';
如果(isset($\u GET['post\u type'])){
$type=$\u GET['post\u type'];
}
//仅将筛选器添加到所需的帖子类型
if('POST_TYPE'=$TYPE){
//将此更改为要显示的值列表
//以“标签”=>“值”格式
$values=数组(
“标签”=>“值”,
'label1'=>'value1',
'label2'=>'value2',
);
?>

此ic包含在WP自定义Post类型中添加自定义筛选器的代码

只需根据您的需求更改代码

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

在第二个函数中,使用作者ID编辑所选记录

 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;
        }
    }
函数wpse45436_admin_posts_filter_restrict_manage_posts(){
$type='post';
如果(isset($\u GET['post\u type'])){
$type=$\u GET['post\u type'];
}
//仅将筛选器添加到所需的帖子类型
if('POST_TYPE'=$TYPE){
//将此更改为要显示的值列表
//以“标签”=>“值”格式
$values=数组(
“标签”=>“值”,
'label1'=>'value1',
'label2'=>'value2',
);
?>

是的,可以做到:;是的,可以做到:;谢谢这有帮助。如果users列中的值是一个用户数组怎么办?您可以通过wp中的循环获取所有用户。在循环内,在数组中传递所有用户ID和用户名。然后是下一个foreach循环(来自上面创建的数组)在上面的WP循环之外,创建选择框的选项,并在选项中传递用户ID和名称..您能告诉我$query->query\u vars['author']=ID从$\u GET;行开始的用户ID作为循环是什么样子吗?$query->query\u vars['author']=$\u GET['selected\u user'];应选择上面创建的选择框的名称。\u usern您只需设置author参数,而不是整个循环。。它将添加author参数来修改循环。。感谢这一点。如果用户列中的值是用户数组,该怎么办?您可以通过wp中的循环获取所有用户。。在循环内传递所有用户ID和数组中的用户名..然后在上述WP循环之外的下一个foreach循环(从上面创建的数组)创建选择框的选项,并在选项中传递用户ID和名称..您能告诉我$query->query\u vars['author']=ID从$\u GET;行得到的用户ID作为循环是什么样子吗?$query->query\u vars['author']=$\u GET['selected\u user'];应选择上面创建的选择框的名称\u user您只需设置author参数,而不必设置整个循环。它将通过添加author参数来修改循环。。