2

For some reason, the most basic wordpress user query i got from this generator

https://generatewp.com/wp_user_query/

is displaying that it has not found any users

    $args = array (
    );

    // The User Query
    $user_query = new WP_User_Query( $args );

    // The User Loop
    if ( ! empty( $user_query->results ) ) {
        foreach ( $user_query->results as $user ) { 
        //do stuff here
       }

   } else { 
   echo "no users found";
   //this is the error i keep getting. so this basic script is not finding any results
  }

am i missing something?

3
  • I think you need to explain, is it show your text "no users found" or what? please edit yours.
    – Jevuska
    Commented Mar 19, 2016 at 16:12
  • edited to clarfiy
    – blank473
    Commented Mar 19, 2016 at 19:17
  • Ok, so as @birgire answer and explain about your an empty array of query arguments, what you can say or do?
    – Jevuska
    Commented Mar 19, 2016 at 19:22

1 Answer 1

2

the most basic wordpress user query [...] is displaying that it has not found any users

You're passing an empty array of query arguments and there's an explicit check for that in the WP_User_Query constructor:

 /**
  * PHP5 constructor.
  *
  * @since 3.1.0
  *
  * @param null|string|array $query Optional. The query variables.
  */
 public function __construct( $query = null ) {
      if ( ! empty( $query ) ) {
           $this->prepare_query( $query );
           $this->query();
     }
}

so that would explain why you get no results in your basic example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.