get_users(…) only returns one user2019 Community Moderator ElectionBest way to get user id for get_users function?Get multiple roles with get_usersget_users is expecting unserialized meta_valueHow to do get_users() with multiple meta_keysHow to get the user description with get_users?get_users meta_querySort get_users by custom fieldget_users() ORDER BY Not WorkingGet_Users Orderby Pageget_users by role returns all users

Update Cursor skipping last row?

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Java: Is there a common interface or superclass for arrays and collections?

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Symbol above others

Query a database specific configuration parameter

Is it worth rebuilding a wheel myself to save money?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Can I legally use front facing blue light in the UK?

aging parents with no investments

Is "plugging out" electronic devices an American expression?

How to move the player while also allowing forces to affect it

"My colleague's body is amazing"

How can I fix this gap between bookcases I made?

Are there any other methods to apply to solving simultaneous equations?

Email Account under attack (really) - anything I can do?

Doomsday-clock for my fantasy planet

Is std::next for vector O(n) or O(1)?

Where does the Shulchan Aruch quote an authority by name?

Why do we use polarized capacitors?

Is it possible for the two major parties in the UK to form a coalition with each other instead of a much smaller party?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

Explicitly parse JSON string vs JSON.deserialize



get_users(…) only returns one user



2019 Community Moderator ElectionBest way to get user id for get_users function?Get multiple roles with get_usersget_users is expecting unserialized meta_valueHow to do get_users() with multiple meta_keysHow to get the user description with get_users?get_users meta_querySort get_users by custom fieldget_users() ORDER BY Not WorkingGet_Users Orderby Pageget_users by role returns all users



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...) is only returning me 1 users though it should return 3. What am I doing wrong?



var_dump($targetUsersIDs);
$targetUsers = get_users(['include' => $targetUsersIDs]);
var_dump($targetUsers);


Output of var_dump($targetUsersIDs);




array (size=3)
0 =>
object(stdClass)[4785]
public 'ID' => string '1' (length=1)
1 =>
object(stdClass)[4784]
public 'ID' => string '2' (length=1)
2 =>
object(stdClass)[4783]
public 'ID' => string '4' (length=1)



Start of the output of var_dump(targetUsers);




array (size=1)
0 =>
object(WP_User) ...










share|improve this question









New contributor




TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


























    1















    I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...) is only returning me 1 users though it should return 3. What am I doing wrong?



    var_dump($targetUsersIDs);
    $targetUsers = get_users(['include' => $targetUsersIDs]);
    var_dump($targetUsers);


    Output of var_dump($targetUsersIDs);




    array (size=3)
    0 =>
    object(stdClass)[4785]
    public 'ID' => string '1' (length=1)
    1 =>
    object(stdClass)[4784]
    public 'ID' => string '2' (length=1)
    2 =>
    object(stdClass)[4783]
    public 'ID' => string '4' (length=1)



    Start of the output of var_dump(targetUsers);




    array (size=1)
    0 =>
    object(WP_User) ...










    share|improve this question









    New contributor




    TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      1












      1








      1








      I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...) is only returning me 1 users though it should return 3. What am I doing wrong?



      var_dump($targetUsersIDs);
      $targetUsers = get_users(['include' => $targetUsersIDs]);
      var_dump($targetUsers);


      Output of var_dump($targetUsersIDs);




      array (size=3)
      0 =>
      object(stdClass)[4785]
      public 'ID' => string '1' (length=1)
      1 =>
      object(stdClass)[4784]
      public 'ID' => string '2' (length=1)
      2 =>
      object(stdClass)[4783]
      public 'ID' => string '4' (length=1)



      Start of the output of var_dump(targetUsers);




      array (size=1)
      0 =>
      object(WP_User) ...










      share|improve this question









      New contributor




      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...) is only returning me 1 users though it should return 3. What am I doing wrong?



      var_dump($targetUsersIDs);
      $targetUsers = get_users(['include' => $targetUsersIDs]);
      var_dump($targetUsers);


      Output of var_dump($targetUsersIDs);




      array (size=3)
      0 =>
      object(stdClass)[4785]
      public 'ID' => string '1' (length=1)
      1 =>
      object(stdClass)[4784]
      public 'ID' => string '2' (length=1)
      2 =>
      object(stdClass)[4783]
      public 'ID' => string '4' (length=1)



      Start of the output of var_dump(targetUsers);




      array (size=1)
      0 =>
      object(WP_User) ...







      php id get-users






      share|improve this question









      New contributor




      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 33 mins ago









      leymannx

      74911022




      74911022






      New contributor




      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      TTTTTT

      1216




      1216




      New contributor




      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          4 Answers
          4






          active

          oldest

          votes


















          2














          The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.






          share|improve this answer








          New contributor




          Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















          • I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

            – TTT
            2 hours ago


















          1














          Somebody has posted this solution and then deleted their post:



          $targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);


          It is where I'm using right now.



          Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).






          share|improve this answer








          New contributor




          TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















          • Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

            – leymannx
            29 mins ago


















          0














          Do it like this



          var_dump($targetUsersIDs);

          $ids = array();
          foreach ( $targetUsersIDs as $id ) $ids[] = $id;

          $targetUsers = get_users(['include' => $ids ] );
          var_dump($targetUsers);


          I hope this may help.






          share|improve this answer
































            0














            You should be using WP_User_Query for this.



            $user_ids = [ 1, 2, 3, 4, 5 ];

            $args = [
            'include' = $user_ids,
            ]

            $user_query = new WP_User_Query( $args );


            Now you can simply use the result in a user loop/foreach.






            share|improve this answer























              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "110"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              TTT is a new contributor. Be nice, and check out our Code of Conduct.









              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333863%2fget-users-only-returns-one-user%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.






              share|improve this answer








              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

                – TTT
                2 hours ago















              2














              The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.






              share|improve this answer








              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

                – TTT
                2 hours ago













              2












              2








              2







              The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.






              share|improve this answer








              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.










              The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.







              share|improve this answer








              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 hours ago









              JulianJulian

              1213




              1213




              New contributor




              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Julian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.












              • I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

                – TTT
                2 hours ago

















              • I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

                – TTT
                2 hours ago
















              I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

              – TTT
              2 hours ago





              I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)

              – TTT
              2 hours ago













              1














              Somebody has posted this solution and then deleted their post:



              $targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);


              It is where I'm using right now.



              Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).






              share|improve this answer








              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

                – leymannx
                29 mins ago















              1














              Somebody has posted this solution and then deleted their post:



              $targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);


              It is where I'm using right now.



              Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).






              share|improve this answer








              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

                – leymannx
                29 mins ago













              1












              1








              1







              Somebody has posted this solution and then deleted their post:



              $targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);


              It is where I'm using right now.



              Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).






              share|improve this answer








              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.










              Somebody has posted this solution and then deleted their post:



              $targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);


              It is where I'm using right now.



              Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).







              share|improve this answer








              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 44 mins ago









              TTTTTT

              1216




              1216




              New contributor




              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              TTT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.












              • Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

                – leymannx
                29 mins ago

















              • Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

                – leymannx
                29 mins ago
















              Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

              – leymannx
              29 mins ago





              Julian's answer explains you why you only got one user returned. Now there's wp_list_pluck() with which you get an array existing merely of user IDs. Which is exactly what include is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs array came from in the first place.

              – leymannx
              29 mins ago











              0














              Do it like this



              var_dump($targetUsersIDs);

              $ids = array();
              foreach ( $targetUsersIDs as $id ) $ids[] = $id;

              $targetUsers = get_users(['include' => $ids ] );
              var_dump($targetUsers);


              I hope this may help.






              share|improve this answer





























                0














                Do it like this



                var_dump($targetUsersIDs);

                $ids = array();
                foreach ( $targetUsersIDs as $id ) $ids[] = $id;

                $targetUsers = get_users(['include' => $ids ] );
                var_dump($targetUsers);


                I hope this may help.






                share|improve this answer



























                  0












                  0








                  0







                  Do it like this



                  var_dump($targetUsersIDs);

                  $ids = array();
                  foreach ( $targetUsersIDs as $id ) $ids[] = $id;

                  $targetUsers = get_users(['include' => $ids ] );
                  var_dump($targetUsers);


                  I hope this may help.






                  share|improve this answer















                  Do it like this



                  var_dump($targetUsersIDs);

                  $ids = array();
                  foreach ( $targetUsersIDs as $id ) $ids[] = $id;

                  $targetUsers = get_users(['include' => $ids ] );
                  var_dump($targetUsers);


                  I hope this may help.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 hours ago

























                  answered 2 hours ago









                  Qaisar FerozQaisar Feroz

                  1,4071217




                  1,4071217





















                      0














                      You should be using WP_User_Query for this.



                      $user_ids = [ 1, 2, 3, 4, 5 ];

                      $args = [
                      'include' = $user_ids,
                      ]

                      $user_query = new WP_User_Query( $args );


                      Now you can simply use the result in a user loop/foreach.






                      share|improve this answer



























                        0














                        You should be using WP_User_Query for this.



                        $user_ids = [ 1, 2, 3, 4, 5 ];

                        $args = [
                        'include' = $user_ids,
                        ]

                        $user_query = new WP_User_Query( $args );


                        Now you can simply use the result in a user loop/foreach.






                        share|improve this answer

























                          0












                          0








                          0







                          You should be using WP_User_Query for this.



                          $user_ids = [ 1, 2, 3, 4, 5 ];

                          $args = [
                          'include' = $user_ids,
                          ]

                          $user_query = new WP_User_Query( $args );


                          Now you can simply use the result in a user loop/foreach.






                          share|improve this answer













                          You should be using WP_User_Query for this.



                          $user_ids = [ 1, 2, 3, 4, 5 ];

                          $args = [
                          'include' = $user_ids,
                          ]

                          $user_query = new WP_User_Query( $args );


                          Now you can simply use the result in a user loop/foreach.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 47 mins ago









                          leymannxleymannx

                          74911022




                          74911022




















                              TTT is a new contributor. Be nice, and check out our Code of Conduct.









                              draft saved

                              draft discarded


















                              TTT is a new contributor. Be nice, and check out our Code of Conduct.












                              TTT is a new contributor. Be nice, and check out our Code of Conduct.











                              TTT is a new contributor. Be nice, and check out our Code of Conduct.














                              Thanks for contributing an answer to WordPress Development Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333863%2fget-users-only-returns-one-user%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How should I use the fbox command correctly to avoid producing a Bad Box message?How to put a long piece of text in a box?How to specify height and width of fboxIs there an arrayrulecolor-like command to change the rule color of fbox?What is the command to highlight bad boxes in pdf?Why does fbox sometimes place the box *over* the graphic image?how to put the text in the boxHow to create command for a box where text inside the box can automatically adjust?how can I make an fbox like command with certain color, shape and width of border?how to use fbox in align modeFbox increase the spacing between the box and it content (inner margin)how to change the box height of an equationWhat is the use of the hbox in a newcommand command?

                              152 Atala Notae | Nexus externi | Tabula navigationis"Discovery Circumstances: Numbered Minor Planets"2000152Small-Body Database

                              Doxepinum Nexus interni Notae | Tabula navigationis3158DB01142WHOa682390"Structural Analysis of the Histamine H1 Receptor""Transdermal and Topical Drug Administration in the Treatment of Pain""Antidepressants as antipruritic agents: A review"