Opened 7 years ago
Last modified 7 years ago
#43391 new defect (bug)
WP_User_Query bug
Reported by: | zkingdesign | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.9.4 |
Component: | Query | Keywords: | |
Focuses: | template | Cc: |
Description
I've got an issue when doing a query with WP_User_Query and trying to list from a specific role AND using 'orderby' => 'post_count'. The query simply fails to list the correct results.
Here are the query arguments:
<?php $args = array( 'fields' => array( 'ID', 'user_login', 'display_name' ), 'role' => 'expert', 'number' => $numPosts, 'offset' => $page > 1 ? $numPosts : 0, 'order' => 'DESC', 'orderby' => 'post_count' );
If I remove the 'role' argument from the query it works, but with the 'role' included it doesn't.
Change History (5)
#2
@
7 years ago
@chetan200891
Yes, the 'expert' role is registered, and it's working OK, it only list users who have that role, but 'orderby' => 'post_count' ain't working.
#3
@
7 years ago
I have tested with below query. It works fine for me. I am getting correct results.
<?php $args = array( 'fields' => array( 'ID', 'user_login', 'display_name' ), 'role' => 'administrator', 'number' => '10', 'order' => 'ASC', 'orderby' => 'post_count' );
Ref. https://codex.wordpress.org/Class_Reference/WP_User_Query
#4
@
7 years ago
This is the query I get, when I dump the $query variable
https://gist.github.com/zkingdesign/2cd5588cee6539427539f8baf34c8f38
Query:
<?php $args = array( 'fields' => array( 'ID', 'user_login', 'display_name' ), 'role' => 'expert', 'number' => $numPosts, 'offset' => $page > 1 ? $numPosts : 0, 'order' => 'DESC', 'orderby' => 'post_count' ); $query = new WP_User_Query( $args ); var_dump($query);
@zkingdesign
Welcome to trac! Have you added new 'expert' role?