How to query users by post count no less than 10

I can see in your code you did mistakes with meta key arguments. You must use underscore instead of hyphen sign. Here is corrected code: $args = array( ‘number’ => 5 , ‘meta_key’ => ‘post_count’, ‘meta_value’ => 10, ‘meta_compare’ => ‘>’, ‘orderby’ => ‘rand’ ); $user_query = new WP_User_Query( $args ); if ( ! empty( … Read more

How to query 5 users in random who have published more than 10 posts

I tried this code and it should work for you In your function.php to make random order available in WP_User_Query function my_random_user_query( $class ) { if( ‘rand’ == $class->query_vars[‘orderby’] ) $class->query_orderby = str_replace( ‘user_login’, ‘RAND()’, $class->query_orderby ); return $class; } add_action( ‘pre_user_query’, ‘my_random_user_query’ ); Source And a query like this // Get all users id … Read more

WP_Query & Duplicate entries

There shouldn’t be a foreach loop inside the while. The while loops over posts, so you don’t need another foreach. The while loop in this context is what WordPress calls “The Loop”. See the section of documentation for The Loop on secondary queries here. So your loop should look like this: <?php while ( $posts->have_posts() … Read more

Nested select statements not working

You need to identify the tables for each of the columns that have the same name. You should also be using an IN statement and not = for the department. I can’t test this since I don’t have your DB but you can try this: $sql = $wpdb->get_results(“SELECT * FROM ” . $wpdb->prefix . “dir_personnel … Read more