Home Rest Api Wp How to get all users in wordpress with rest api hook?

How to get all users in wordpress with rest api hook?

by therichpost
How to add custom meta title and meta description in Wordpress?

Hello, welcome to therichpost.com. In this post, I will tell you How to get all users in wordpress with rest api hook? WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.

rest_api_init function will user to make api.

Today I am introducing Wordpress Rest Api. Rest Api is very good feature or hook in wordpress. There are some defaults Rest Api in Wordpress and we can also create our own Rest Api in Wordpress.

Here is the working image to get users names in Wordpress with Rest Api:

I am working with Wordpress from long 4 years but today first time I created Wordpress Rest Api.

Finally here is the working Wordpress Rest Api and you need to add this code into your theme’s functions.php file:

add_action( ‘rest_api_init’, function () {
register_rest_route( ‘wp/v2’, ‘/getusers/’, array(
‘methods’ => ‘GET’,
‘callback’ => ‘get_users_names’
) );
} );

function get_users_names()
global $wpdb;
$myArr = array();
$wp_user_search = $wpdb->get_results(“SELECT ID, display_name FROM $wpdb->users ORDER BY ID”);

foreach ( $wp_user_search as $userid ) {

$myArr[] = stripslashes($userid->display_name);

$myJSON = json_encode($myArr);
echo $myJSON;

I personally liked it very much Wordpress Rest Api. We will use this in Angularjs 2 in future.

There are so many hooks in wordpress and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

You may also like


khaled February 13, 2018 - 12:57 pm

Hi I want to access wordpress plugin list in my other website which is non wordpress.

How to do ?

Site 1(Wordpress) —–> plugin names (Akismet,woocommerce) ——–> access the names only in my site 2 (Non wordpress).

Just as a information I want to access it.

therichpost February 13, 2018 - 2:35 pm

Hello Khaled, Thank you for your comment.
You can use your Wordpress website information in your non wordpress website with api’s.
With wordpress rest api’s, you can any informations and used that one into your non-wordpress site.

Thank you


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.