I want to show all the contributors by the Designation. Following code is only pull the records and order by ID But I need to data order by Designation:
function contributors() {
global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY id DESC");
foreach ($authors as $author ) {
echo get_wp_user_avatar($author->ID);
the_author_meta('designation', $author->ID);
the_author_meta('fullname', $author->ID);
the_author_meta('company', $author->ID);
the_author_meta('address', $author->ID);
the_author_meta('phone', $author->ID);
}
}
Could you please help me out?
Thanks.
I want to show all the contributors by the Designation. Following code is only pull the records and order by ID But I need to data order by Designation:
function contributors() {
global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY id DESC");
foreach ($authors as $author ) {
echo get_wp_user_avatar($author->ID);
the_author_meta('designation', $author->ID);
the_author_meta('fullname', $author->ID);
the_author_meta('company', $author->ID);
the_author_meta('address', $author->ID);
the_author_meta('phone', $author->ID);
}
}
Could you please help me out?
Thanks.
Share Improve this question asked Feb 11, 2022 at 17:40 Manoj MauryaManoj Maurya 213 bronze badges 2 |1 Answer
Reset to default 2I got the answer after went through WP_User_Query
documentation. Following is the final query:
$args = [
'role__not_in' => 'Administrator',
'meta_key' => 'designation',
'meta_query '=> [
'meta_key' => 'designation'
],
'orderby' => array(
'meta_value'=>'ASC'
)
];
$my_user_query = new WP_User_Query( $args );
WP_User_Query
can do what you're doing, and it can filter by user meta. Also useget_user_meta
notthe_author_meta
– Tom J Nowell ♦ Commented Feb 11, 2022 at 21:02