如何在wordpress用户元数据中使用MySQL选择查询并从其他表中左连接? [英] How to use MySQL select query in word press user meta data and left join from other table?

查看:24
本文介绍了如何在wordpress用户元数据中使用MySQL选择查询并从其他表中左连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果他处于活动状态,我需要获取用户计数.

I need to get the user count if he is active.

我有两张桌子:

  1. 用户
  2. wp_user_meta

wp_user_meta 表中,用户的一些详细信息以序列化形式存储,其中用户 active_status 是.

In a wp_user_meta table the some details of user are stored in serialised form there were the user active_status is.

如何编写查询以获取具有上述条件的用户数

how do I write a query to get user count with above conditions

我曾经使用 wordpress 方法获取用户元数据

I used to get user meta using wordpress method

喜欢:

$user_meta = get_user_meta( 98 );

$all=$user_meta['coupon_user_meta'][0];

$unser=unserialize($all);

print_r($unser); 

输出为

Array ( [active_status] => active [subscribe] => yes [avatar] => [confirmation_hash] => )

如何编写查询?

谢谢大家最后我硬编码了一些.它对我有用.请查看此代码.

Thank you all lastly i have hard-coded some. its works for me. please review this code.

$data = array();
$results = $wpdb->get_results("SELECT * FROM wp_users");

if(!empty($results)){

    foreach($results as $row){
        $person_id= $row->ID;
        $data[] = person_id;
    }
}
$num=0;
$check=$meta=$unserial=NULL;
foreach($data as $user){

    $check=get_user_meta($user);
    $meta=$check['coupon_user_meta'][0];


$unserial=unserialize($meta);


$co=$unserial['active_status'];


    if($co=="active"){
        $num++;

    }


}
echo $num;

推荐答案

试试这个代码.

<?php
$allusers = get_users( $args = array() );
foreach ( $allusers as $user ) {
   if($user->active_status == 'active'){
    $active_user[] = $user->active_status;
   }
}

$count = sizeof($active_user);
?>

这篇关于如何在wordpress用户元数据中使用MySQL选择查询并从其他表中左连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆