[wp-trac] [WordPress Trac] #54310: WP_User_Query does not return results in the save format if fields set to all_with_meta and doesn't return any meatadata
WordPress Trac
noreply at wordpress.org
Fri Oct 22 17:54:27 UTC 2021
#54310: WP_User_Query does not return results in the save format if fields set to
all_with_meta and doesn't return any meatadata
--------------------------+------------------------------------------
Reporter: pbearne | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version:
Severity: normal | Keywords: needs-patch needs-unit-tests
Focuses: |
--------------------------+------------------------------------------
Digging into WP_User_Query if you set the fields to all_with_meta it
returns an array index by the user_ID veers a keyed list for all other
results
this is the
{{{
if ( 'all_with_meta' === $qv['fields'] ) {
cache_users( $this->results );
$r = array();
foreach ( $this->results as $userid ) {
$r[ $userid ] = new WP_User( $userid, '',
$qv['blog_id'] );
}
$this->results = $r;
} elseif ( 'all' === $qv['fields'] ) {
foreach ( $this->results as $key => $user ) {
$this->results[ $key ] = new WP_User(
$user, '', $qv['blog_id'] );
}
}
}}}
I feel we should return the same shape array for both so propose to set
the all to array index to the User_ID's
with a change like this
{{{
if ( 'all_with_meta' === $qv['fields'] ) {
cache_users( $this->results );
$r = array();
foreach ( $this->results as $userid ) {
$r[ $userid ] = new WP_User( $userid, '',
$qv['blog_id'] );
}
$this->results = $r;
} elseif ( 'all' === $qv['fields'] ) {
foreach ( $this->results as $user ) {
$this->results[ $user->ID ] = new WP_User(
$user, '', $qv['blog_id'] );
}
}
}}}
And better still it doesn't return the meta values !!!
So let's add this as well
{{{
if ( 'all_with_meta' === $qv['fields'] ) {
cache_users( $this->results );
$r = array();
foreach ( $this->results as $userid ) {
$r[ $userid ] = new WP_User( $userid, '',
$qv['blog_id'] );
$r[ $userid ]->meta = get_user_meta(
$userid );
}
$this->results = $r;
} elseif ( 'all' === $qv['fields'] ) {
foreach ( $this->results as $key => $user ) {
$this->results[ $key ] = new WP_User(
$user, '', $qv['blog_id'] );
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54310>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list