Skip to main content
Made the code more readable
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Ok, so right now I can easily echo the number of posts that has a specific meta_key and meta_value:

<?php $query = new WP_Query( 
    array( 
        'meta_key' => 'usp-custom-1', 
        'meta_value' => get_permalink() 
    )  
);  
echo $query->found_posts; ?>

I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.

I'm trying this:

<?php $query = new WP_User_Query( 
    array(  
        'meta_key' => 'cash_out_status',  
        'meta_value' => 'pending' 
    )  
);  
echo $query->found_users; ?>

But the above doesn't display anything.

I guess I'm making a mistake somewhere in the code.

Any help would be greatly appreciated.

Thanks.

Ok, so right now I can easily echo the number of posts that has a specific meta_key and meta_value:

<?php $query = new WP_Query( array( 'meta_key' => 'usp-custom-1', 'meta_value' => get_permalink() ) ); echo $query->found_posts; ?>

I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.

I'm trying this:

<?php $query = new WP_User_Query( array(  'meta_key' => 'cash_out_status',  'meta_value' => 'pending' ) ); echo $query->found_users; ?>

But the above doesn't display anything.

I guess I'm making a mistake somewhere in the code.

Any help would be greatly appreciated.

Thanks.

Ok, so right now I can easily echo the number of posts that has a specific meta_key and meta_value:

$query = new WP_Query( 
    array( 
        'meta_key' => 'usp-custom-1', 
        'meta_value' => get_permalink() 
    )  
);  
echo $query->found_posts;

I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.

I'm trying this:

$query = new WP_User_Query( 
    array(  
        'meta_key' => 'cash_out_status',  
        'meta_value' => 'pending' 
    )  
);  
echo $query->found_users;

But the above doesn't display anything.

I guess I'm making a mistake somewhere in the code.

Any help would be greatly appreciated.

Thanks.

Source Link
robert0
  • 203
  • 2
  • 11

Echo the number of users using WP_User_Query?

Ok, so right now I can easily echo the number of posts that has a specific meta_key and meta_value:

<?php $query = new WP_Query( array( 'meta_key' => 'usp-custom-1', 'meta_value' => get_permalink() ) ); echo $query->found_posts; ?>

I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.

I'm trying this:

<?php $query = new WP_User_Query( array(  'meta_key' => 'cash_out_status',  'meta_value' => 'pending' ) ); echo $query->found_users; ?>

But the above doesn't display anything.

I guess I'm making a mistake somewhere in the code.

Any help would be greatly appreciated.

Thanks.