1

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?

  • I think you need to explain, is it show your text "no users found" or what? please edit yours. – Jevuska Mar 19 '16 at 16:12
  • edited to clarfiy – blank473 Mar 19 '16 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 Mar 19 '16 at 19:22
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, privacy policy and cookie policy

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