PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] How can I get the current user id in wordpress by making an ajax request from the website's front end (built in react on the same domain)

 January 18, 2022     ajax, javascript, php, reactjs, wordpress     No comments   

Issue

I have a wordpress website where react is used for all the front end components. I need to somehow fetch the currently logged-in user's id using the wordpress REST API via an ajax request. The request to the REST API needs to be authenticated in order to get this information but not sure how without the user's credentials in the first place.

Thanks in advance.


Solution

You can fetch a list of all the users using the Wordpress Rest api and then filter the result of a particular user based on your criteria.

Ref:- Fetch all users

Alternatively, You can fetch current user using this endpoint from the rest API provided by wordpress.

Ref:- Fetch current user



Answered By - Akshay Mathur
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing