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 ...
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-...
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/ ...
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. ...
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 ...
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 ...
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 ...
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)...
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 ...
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 ...
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 !== '...
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 ...
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
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 ...
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. ...
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.
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 ...
6
votes
How do I access the body of a WP API request in a custom route?
You can use $request->get_body()
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',
...
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]=...
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 ...
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 $...
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 ...
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 ...
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 ...
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 ...
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/
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/...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
wp-api × 205rest-api × 103
api × 49
json × 22
plugins × 16
custom-post-types × 15
plugin-development × 12
plugin-json-api × 12
php × 10
authentication × 9
javascript × 8
ajax × 7
post-meta × 7
backbone × 6
custom-taxonomy × 5
woocommerce-offtopic × 5
custom-field × 5
media × 5
oauth × 5
posts × 4
wp-query × 4
tags × 4
curl × 4
filters × 3
meta-query × 3