query.users_builder

/ Database / query.users_builder

 

Title : query.users_builder
Purpose : query.users_builder is used to create complex queries for users. It requires additional attributes to be used with query.users_builder. For details of various JSON parameters check WP_User_Query Class
Syntax :
Input Parameters : part=start

part=meta_query

part=date_query

part=run

fields (string|array) – Which fields to return. Defaults to all.

  • ‘ID’ – Return an array of user id’s.
  • ‘display_name’ – Return an array of user display names.
  • ‘login’ / ‘user_login’ – Return an array of user login names.
  • ‘nicename’ / ‘user_nicename’ – Return an array of user nicenames.
  • ’email’ / ‘user_email’ – Return an array of user emails.
  • ‘url’ / ‘user_url’ – Return an array of user urls.
  • ‘registered’ / ‘user_registered’ – Return an array of user registered dates.
  • ‘all (default) or all_with_meta’ – Returns an array of WP_User objects. Must pass an array to subset fields returned. *’all_with_meta’ currently returns the same fields as ‘all’ which does not include user fields stored in wp_usermeta. You must create a second query to get the user meta fields by ID or use the __get PHP magic method to get the values of these fields.

Additional attributes

  • part:
    start | meta_query | date_query | run

    It allows us to break complex queries into parts. part attribute is used when we use ‘users_builder‘ attribute. It gives us the ability to add or remove parts of a query based on conditions.

    When the part is start it destroys all existing parts and creates a new query, so it is important that when you are breaking a query into parts, part=start is first. Part meta_query indicates that JSON value is to be used for creating meta query and part date_query indicates date query it is applied to user_registered field.

    If the part is not used, then query executes immediately, else it only executes when it finds part=run.

    For more details, visit WP_User_Query

Return Value : (object) (WP_User_Query)
Example 1 :
Code :
Output : user_logins of all the Administrators who joined before August 4th, 2020
Description : In this example we are displaying all the user_logins of Administrator who joined before August 4th, 2020.
Categories
Most Popular

Leave a Reply

Your email address will not be published. Required fields are marked *