Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:26:36+00:00 2026-06-11T06:26:36+00:00

I am trying to use a WordPress User Query to create a list of

  • 0

I am trying to use a WordPress User Query to create a list of users that is ordered by a custom meta value. Its a simple numeric value, going from 1 to 100, so 1 needs to be displayed first, 100 last, etc.

This is my attempt, which has failed miserably:

<?php

    $args  = array(
        'role' => 'Author',
        'meta_key' => 'order-number',
        'orderby' => 'order-number',
        'order' => 'asc',  
    );

$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();

if (!empty($authors))
{
    echo '<div style="float:left;">';
    foreach ($authors as $author)
    {
        $author_info = get_userdata($author->ID);
        echo '<div class="post team-member"><div class="image">';
        echo get_avatar( $author_info->ID, 91 );
        echo '</div>';
        echo '<div class="content"><div class="title"><a href="/author/' . $author_info->user_login . '">' . $author_info->user_firstname . ' ' . $author_info->user_lastname . '</a></div>';
        echo '' . substr( get_the_author_meta('user_description',$author_info->ID) , 0 , 100 ) . '...'; 
        echo '</div></div>';
    }
    echo '</div>';
} else {
    echo 'No authors found';
}

    ?>

I think the problem is that wp_user_query does not support custom fields in orderby – so I need a solution that works around this.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:26:37+00:00Added an answer on June 11, 2026 at 6:26 am

    Correct. The orderby parameter can only accept possible values of ‘login’ (default), ‘nicename’, ’email’, ‘url’, and ‘registered’.

    A dirty fix would be something like this:

    <?php
    global $wpdb; //Ignore this line if you're not within a function
    $order = $wpdb->get_results("SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_key='order-number' ORDER BY meta_value ASC", "ARRAY_N");
    $authors = array();
    foreach($order as $aid)
        $authors[] = new WP_User($aid[0]);
    
    if (!empty($authors))
    {
        echo '<div style="float:left;">';
        foreach ($authors as $author)
        {
            $author_info = get_userdata($author->ID);
            echo '<div class="post team-member"><div class="image">';
            echo get_avatar( $author_info->ID, 91 );
            echo '</div>';
            echo '<div class="content"><div class="title"><a href="/author/' . $author_info->user_login . '">' . $author_info->user_firstname . ' ' . $author_info->user_lastname . '</a></div>';
            echo '' . substr( get_the_author_meta('user_description',$author_info->ID) , 0 , 100 ) . '...'; 
            echo '</div></div>';
        }
        echo '</div>';
    } else {
        echo 'No authors found';
    }
    

    This is largely untested, so I can’t guarantee this will work straight out of the gate, but it should get you started.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use custom meta boxes in wordpress. My goal at the moment
i'm trying to create a Dynamic Sub-menu to use it in Wordpress, Something like
I am trying to integrate my site to use the bbpress/wordpress user system. All
I am working in Wordpress trying to use an ajax request to fetch user
I'm trying to use wordpress' media upload popup in a custom plugin I'm working
I'm trying to learn MySQL queries for use with Wordpress.... What I do know
I am trying use a Java Uploader in a ROR app (for its ease
I'm trying to use Widget Logic (wordpress plugin) to display a widget when viewing
First time trying to use the password protected visibility option on a Wordpress page,
I'm trying to make a page for use with wordpress and it's almost working,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.