95 votes
Accepted

WP Rest API - How to get featured image

You can get it without plugins by adding _embedas param to your query /?rest_route=/wp/v2/posts&_embed /wp-json/wp/v2/posts?_embed
Eslam Mahmoud's user avatar
73 votes

Get WP Navigation Menu from REST API V2

Since I don't like it myself when the top answer is "Install plugin X", here is how I solved it: Menus are currently not available in the WP Rest. So what you need to do is register your own custom ...
Liren's user avatar
  • 831
17 votes

WP Rest API - How to get featured image

I would NOT use the better rest API plugin. It did add featured images to the rest api but it also broke it. This is the simplest solution I was able to find that actually worked. Add the following ...
Null TX's user avatar
  • 321
11 votes

WP REST API only returning partial list of users

To anyone who might still be hitting this problem, here's a checklist: Make sure you are authenticated AND your user has the list_users capability. Example: When adding a custom role, I make sure ...
Abe Caymo's user avatar
  • 223
8 votes

WP Rest API - How to get featured image

You can get the name of the image with this path: array_name._embedded['wp:featuredmedia']['0'].source_url
RobK's user avatar
  • 81
8 votes

Get WP Navigation Menu from REST API V2

@Liren answer works well. However few beginners may not able to adjust the route. Here is the code that works well with WordPress Rest API v2 with minimum modification. Replace your menu name only in ...
Deepak Rajpal's user avatar
6 votes

WP Rest API - How to get featured image

Take a look at a plugin called Better REST API Featured Image. It adds the featured image URL to the original API response.
Michael Cropper's user avatar
5 votes

How to Securely and remotely Create new user in wordpress using Rest API

To create any content on a WordPress website via REST-API your must use authentication. You have two options for getting OAuth tokens, Detailed explanations in the following link: https://developer....
Moshe Harush's user avatar
4 votes

WP REST API - Retrieve content from page

To retrieve a page by slug, just use /wp-json/wp/v2/pages/?slug=your-page-name-here, with "your-page-name-here" obviously being the slug of your page.
Spartacus's user avatar
  • 397
4 votes
Accepted

how to get nonce using json api

You need to call like below. API call:- http://78.47.177.214/blog/api/get_nonce/?json=get_nonce&controller=posts&method=create_post Responce:- {"status":"ok","controller":"posts","method":"...
Devendra Sharma's user avatar
4 votes
Accepted

Retrieve all users from wordpress database via REST/JSON API

Thanks to stackoverflow user Milap ! You can get all users even they have not created any post, for that you need to modify rest-api plugin. Open wp-content/plugins/rest-api/lib/endpoints/class-wp-...
TimeParadox's user avatar
4 votes

WP REST API only returning partial list of users

I think it depends on the specifics on what your looking for, you can gain the most control by making your own route tough, the users route is more meant to list out users, not exactly search them as ...
Jordan Ramstad's user avatar
4 votes
Accepted

WP REST API only returning partial list of users

After much reading I found the reason why all users are not returned with the straight-forward HTTP request for WP REST API: This is a non-authenticated request, therefore only publicly available ...
MakeCodeNotWar's user avatar
3 votes
Accepted

ping_status in JSON REST API

According to WordPress Codex, pings tells Whether the current post is open for pings. In human words, A ping is a “this site has new content” notification that invites search engine bots to visit ...
Jack Song's user avatar
  • 391
3 votes

Get WP Navigation Menu from REST API V2

I opted for the simplest way to do it, still keeping it dynamic so that you can fetch more than one menu. /** * Returns menu items in a array based on the navigation menu id passed * * @param ...
Mel Macaluso's user avatar
2 votes

Wordpress JSON API restrict to specific domain

More reliable will be allowing specific IP instead of domain using REMOTE_ADDR header. You can use HTTP_REFERRER header but it is not reliable. You can do it via using rest_authentication_errors ...
Sisir's user avatar
  • 7,782
2 votes

Why aren't tags and categories added in post request to WP Rest API

You are using name in your terms. In default, try to use the existing term id ( in your case, cat ID and tag ID ). If you see https://plugins.trac.wordpress.org/browser/rest-api/trunk/lib/endpoints/...
Jevuska's user avatar
  • 1,160
2 votes

WP REST API - Retrieve content from page

Try /wp-json/wp/v2/pages/<id>. Not sure if retrieving a page by name is possible using the REST API.
Z. Zlatev's user avatar
  • 1,149
2 votes

WP Rest API - How to get featured image

I made a shortcut to my image by adding it directly to the API response. //Add in functions.php, this hook is for my 'regions' post type add_action( 'rest_api_init', 'create_api_posts_meta_field' ); ...
lakewood's user avatar
  • 141
2 votes

Why use JSON API to display recent posts?

There is no real reason at all, and the reasons are: you need to load more JS, either as more code, or even worse extra, JS files You need to do 2 requests to the sever instead of one. Since the ...
Mark Kaplun's user avatar
  • 23.4k
2 votes

Why use JSON API to display recent posts?

The JSON API is just a wrapper for WP_Query bundled with RESTful endpoints (add_rewrite_rules). Its a way to speed up production by providing a framework which you otherwise would have to code ...
Pedro Coitinho's user avatar
2 votes

WP Rest API - How to get featured image

Paste this code in your theme's functions.php file and use this key for the featured image: featured_image_url function post_featured_image_json( $data, $post, $context ) { $featured_image_id = $...
GNELEZIE's user avatar
2 votes
Accepted

How to create WordPress custom end point with multiple parameters?

When you register a route, parameters accepted via the query string (eg. ?a=b&c=d) are not registered as part of the endpoint, like you have done. Those parameters just need to be defined in the ...
Jacob Peattie's user avatar
1 vote

Add external js file to footer with id

You can use the script_loader_tag hook function enqueue_validation_script() { wp_register_script( 'validation', 'https://www.asd.in/script.php?id=3ff00a469474bbe71a9218a7f0377518', array( 'jquery'...
Shibi's user avatar
  • 1,813
1 vote
Accepted

How to alter WP-JSON main query or best practise for custom endpoints

You are doing the right thing. In theory you can probably intercept the "normal" API request and modify the relevant wp_query to whatever you need, but this will mean that you are changing and ...
Mark Kaplun's user avatar
  • 23.4k
1 vote

Wordpress JSON API returns normal site page in html. How do I get it to give me JSON?

I had the same problem and I solved it setting the permalink in the wordpress and also changing the .htaccess (see https://www.wpbeginner.com/wp-tutorials/how-to-fix-wordpress-posts-returning-404-...
Rogerio P's user avatar
1 vote

Wordpress JSON API returns normal site page in html. How do I get it to give me JSON?

I'm likely doing it wrong, but when I form my requests for a Wordpress installation at http://www.example.com/ like this: http://www.example.com/index.php?rest_route=/my/rest/route/here I end up ...
Mattygabe's user avatar
  • 111
1 vote

WP Rest API - How to get featured image

Try following way .................... URL: /wp-json/wp/v2/posts?_embed image: json["_embedded"]["wp:featuredmedia"][0]["source_url"], It's working fine.try
MAM.AASIM's user avatar
1 vote
Accepted

wp json api - get posts by category

I solved the problem in a different way. First I extracted all the posts by including category name inside of it. Check the answer below. public function module_data() { global $json_api; ...
rgk's user avatar
  • 111
1 vote
Accepted

JSON API plugin, Get posts by category return no post

get_category_posts/?slug=cat1&post_type=project I forgot to set post_type.
Amino's user avatar
  • 323

Only top scored, non community-wiki answers of a minimum length are eligible