php 按自定义用户元过滤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按自定义用户元过滤相关的知识,希望对你有一定的参考价值。

<?php
add_action('pre_user_query', 'my_user_query');

function my_user_query($userquery){

    if(!is_admin())
        return;


//    if('wallet'==$userquery->query_vars['orderby']) {//check if church is the column being sorted
//        global $wpdb;
//        $userquery->query_from .= " JOIN $wpdb->usermeta AS alias ON ($wpdb->users.ID = alias.user_id) ";//note use of alias
//        $userquery->query_where .= " AND alias.meta_key = 'wallet' ";//which meta are we sorting with?
//        $userquery->query_orderby = " ORDER BY CAST(alias.meta_value  AS UNSIGNED) ".($userquery->query_vars["order"] == "ASC" ? "asc " : "desc " ) ;//set sort order
//
//        //print_pre($userquery);
//    }


}

if( is_admin()){
    add_action('pre_get_users', function($query){
        $orderby = $query->query_vars["orderby"];
        $meta_query = array(
            'relation' => 'OR',
            array(
                'key' => $orderby,
                'compare' => 'NOT EXISTS'
            ),
            array(
                'relation' => 'OR',
                array(
                    'key' => $orderby,
                    'value' => 1
                ),
                array(
                    'key' => $orderby,
                    'value' => 1,
                    'compare' => '!='
                )
            )
        );
        $query->set('meta_query', $meta_query);
        $order = $query->query_vars["order"] == "asc" ? "ASC" : "DESC";//set sort order
        $query->set('orderby', array('meta_value_num' => $order, 'date' => $order));

    },999);
}



?>

以上是关于php 按自定义用户元过滤的主要内容,如果未能解决你的问题,请参考以下文章

按自定义日期范围输入过滤 wordpress 帖子

php Сustom类别过滤器解析URL类别过滤器按自定义过滤器按属性自定义过滤器自定义排序

WP 按自定义元键归档顺序

在 Django admin 中按自定义日期范围过滤

Google Analytics:按自定义维度过滤

按自定义字段过滤帖子 - url 正确更新但过滤不起作用