Hot answers tagged

71 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 ...
user avatar
  • 811
29 votes

Get post count in wp rest API v2 and get all categories

The WP Rest API sends the total count(found_posts) property from WP_Query. in a header called X-WP-Total. FOR POSTS: you can make a call to posts endpoint of the REST API http://demo.wp-api.org/wp-...
user avatar
  • 2,811
22 votes
Accepted

Hiding WordPress REST API v2 endpoints from public viewing

Is this meant to be used on sites in production? Yes. Many sites have been already using it. Is there a security risk to allowing endpoints to be viewed by anyone, such as /wp-json/wp/v2/users/ ...
user avatar
  • 3,349
12 votes
Accepted

Implementing Isomorphic JavaScript (React JS) in Wordpress?

I don't think using React.js without Node.js (or at least V8 or rhino etc) counts as isomorphic, as isomorphic means that you are building JavaScript to run in the browser AND on the server. ...
user avatar
10 votes
Accepted

WP-API v2 Custom Endpoint Response Formatting

You can call the REST API methods to prepare your output in the same way that the plugin does by default, this will also allow any plugins to tie into the output as you have used the ACF plugin as ...
user avatar
9 votes

How do I access the body of a WP API request in a custom route?

In a previous answer is was able to access the data in a custom endpoint using $parameters = $request->get_query_params(); Check the query params for option $parameters['option'] Two options for ...
user avatar
  • 9,439
9 votes

How do I access the body of a WP API request in a custom route?

You can use $request->get_json_params() which will return an array of key => values. With these conditions(possibly a few more): The client sending the request has Content-Type: application/json ...
user avatar
  • 191
9 votes
Accepted

Custom endpoint and X-WP-TotalPages (headers)

I had a quick look and here's how the headers are set in the WP_REST_Posts_Controller::get_items() method: $response = rest_ensure_response( $posts ); // ... $response->header( 'X-WP-Total', (int)...
user avatar
  • 63.8k
9 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 ...
user avatar
  • 103
8 votes
Accepted

Show popular post in another php website via WP REST JSON API

I will give you a small answer to your update, doing this with the WP API. The API have the possibilities to use the WP_Query like also in core, but about the get parameters in the url. A URL to pull ...
user avatar
  • 16.6k
8 votes
Accepted

Unset data in custom post type WordPress API (wp-json)

If possible, only the examples shown in internet is: function qod_remove_extra_data($data, $post, $context) { // We only want to modify the 'view' context, for reading posts if ($context !== '...
user avatar
8 votes

Get post count in wp rest API v2 and get all categories

In case it's not clear how to actually access the header (with the post count) from the Ajax request, following is how to do it with jQuery .get. The key is that the callback function has an optional ...
user avatar
  • 113
8 votes
Accepted

Get more than 10 posts in a specific category with the wordpress api

See if your url is correct. Example: website.com/wp-json/wp/v2/posts/?categories=3&per_page=‌​50
user avatar
7 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 ...
user avatar
7 votes

Hiding WordPress REST API v2 endpoints from public viewing

Is it possible to allow only authorized users to access an endpoint? It is possible to add a custom permission callback to your API endpoint which requires authentication to view the content. ...
user avatar
7 votes
Accepted

WP API V2 returning Invalid User ID

Wordfence blocks the User endpoint from the public. In settings there is a checkbox you can unselect to make it visible in the WP Rest API again.
user avatar
  • 282
7 votes
Accepted

WP Rest API v2 filter and display latest post with specific tag

You can actually find extensive documentation on wordpress.org. But let's have a look at this particular example: https://demo.wp-api.org/wp-json/wp/v2/posts?per_page=5&tags=3 The 5 in there is ...
user avatar
  • 5,431
6 votes

How do I access the body of a WP API request in a custom route?

You can use $request->get_body()
user avatar
6 votes

Get the Category Name instead of ID from WP-API

This code will add categories_names field to wp rest api response: function wpse_287931_register_categories_names_field() { register_rest_field( 'project', 'categories_names', ...
user avatar
  • 2,382
5 votes
Accepted

Query WP REST API v2 by multiple meta keys

Adding a custom endpoint is pretty straightforward. I also modified the url to look more like http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=...
user avatar
  • 9,439
5 votes
Accepted

wp rest api v2 return json_no_route

OK, i find my answer. Just ask it here and as dear Charles sayed, they answered me, so fast, the answer is: By default, WP-API v1 takes priority over v2. If v1 is installed and activated, then v2 ...
user avatar
  • 353
5 votes
Accepted

Can I list all installed plugins/versions and wp version from API

Yes, there is a way to get that information programmatically. WordPress Version Info The WordPress version exists as a global, but you can also get it using the get_bloginfo() function: global $...
user avatar
  • 4,400
5 votes
Accepted

wordpress custom endpoint multiple params

As I said in the comment, your endpoint worked fine for me. And you said, I managed to stop giving error, but I can't get what I pass in parameters, I put the regular expression, it keeps giving ...
user avatar
  • 31.4k
5 votes
Accepted

Are there server performance benefits to fetching only specific fields when querying the REST API?

I understand that having less data being downloaded improves the experience to the end user, but my question is related to the actual server performance, would the response be faster? Would adding ...
user avatar
  • 51.7k
4 votes

Implementing Isomorphic JavaScript (React JS) in Wordpress?

I think we're not far away from being able to achieve this in a pretty sensible way. The WordPress.com website has already moved over to a JavaScript application powered by a REST API with Node.js and ...
user avatar
  • 417
4 votes

OAuth signature does not match

Make sure that signature request is handled correctly: http://oauth1.wp-api.org/docs/basics/Signing.html If you're using POSTMAN you can set it to OAuth 1.0 under Authorization and then select the ...
user avatar
  • 2,673
4 votes
Accepted

Get WP Navigation Menu from REST API V2

There is a navigation menu plugin extension for the REST API v2: https://wordpress.org/plugins/wp-api-menus/
user avatar
4 votes
Accepted

Wordpress Rest API

What version of the REST API are you using? If you're using the version that's bundled with WordPress 4.4 (ie, v2), you'll need to change your url to something like http://example.com/wp-json/wp/v2/...
user avatar
  • 10.2k
4 votes
Accepted

Get all tags not just first 10 with wp api 2.0

If we look at the WP_REST_Controller::get_collection_params() method, we can see the minimum is 1 and the maximum is 100: 'per_page' => array( 'description' => __( 'Maximum number of ...
user avatar
  • 63.8k
4 votes
Accepted

node-wpapi: how to handle authentication?

I'm the author of the node-wpapi library, thanks for checking it out. Unfortunately we do not currently support any external authentication scheme out of the box, because WordPress itself does not ...
user avatar
  • 155

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