80

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


61

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 endpoint and then just call that route from your application that needs it. So you would include something like this (in your functions.php, plugin, wherever): ...


27

Just add the next parmater into the function register_post_type, it can be before 'menu_position'parameter. 'show_in_rest' => true if you're using a plugin to register your posttype you can use the next code: add_action( 'init', 'add_anuncios_to_json_api', 30 ); function add_anuncios_to_json_api(){ global $wp_post_types; $wp_post_types['anuncio']-&...


14

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 code to your functions.php: <?php function post_featured_image_json( $data, $post, $context ) { $featured_image_id = $data->data['featured_media']; // ...


8

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 content from Post Status would look like this: http://example.com/wp-json/posts To pull content with WP_Query parameters you’re used to, you could do it like ...


7

You can get the name of the image with this path: array_name._embedded['wp:featuredmedia']['0'].source_url


6

To show custom post types in version 2, you need to add 'show_in_rest' => true in the register_post_type function arguments, then your posts with that custom post type will be available at the endpoint: wp-json/wp/v2/your-custom-post-type. Source: http://scottbolinger.com/custom-post-types-wp-api-v2/


6

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 to add the list_users capability. The user should also be logged in (what authenticated means) when making the request. By default, only users who have ...


5

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


5

@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 wp_get_nav_menu_items() function. If menu name and slug does not work (Return false), use Menu ID (visible in Dashboard while editing that Menu). function ...


5

Take a look at a plugin called Better REST API Featured Image. It adds the featured image URL to the original API response.


5

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.wordpress.org/rest-api/using-the-rest-api/authentication/


4

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":"create_post","nonce":"92f31d49b5"}


4

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-rest-users-controller.php file, you will find below code on line number 106, if ( ! current_user_can( 'list_users' ) ) { $prepared_args['has_published_posts'...


4

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 there is a pretty crazy amount of stuff you could be wanting to search based off of, and doing that all through parameters might get difficult. I am not saying ...


3

SECURITY NOTE: This (and the other solutions) shouldn't be used unless you have a way to override the Content-Type: text/html header that WP Super Cache sends with the appropriate application/json value. Sending JSON as text/html will cause the browser to render it as HTML, which could potentially be an XSS vector. It looks like that needs to be done at the ...


3

I think it is better that you switch to the current beta, version 2, publish on github. This version is much better in possibilities and performance. In this version it is possible that you get a result for the search term, Iike GET /wp-json/wp/v2/posts?s=awesome.


2

If you know the key of your meta field then you can use this filter: add_filter( 'json_prepare_post', function ( $data, $post, $context) { $data['myextradata'] = array( 'somekey' => get_post_meta( $post['ID'], 'abcdef', true ), ); return $data; }, 10, 3 ); Replace abcdef with the key of your meta field. Then, if you get a posts' json,...


2

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 filter. add_filter( 'rest_authentication_errors', 'wpse150207_filter_incoming_connections' ); function wpse150207_filter_incoming_connections( $errors ){ $...


2

I assume you're using this plugin? From the docs it seems you can use standard query arguments, so try: /api/get_posts/?job_loc=yangon&page=10&count=5


2

As @TheDeadMedic mentioned the API will exclude any meta with underscore. It's not a good idea to remove the underscore as it might break something in your code or dependencies, however you can try adding a code like this in your functions.php to unprotect the desired meta add_filter( 'is_protected_meta', 'wp692_meta_unprotect', 10, 2 ); function ...


2

If you look at the description for the different tables used by WordPress, the columns described as "auto_increment" will be unique. I am not sure what you are doing though. The URL structure you are using is not one that I recognize. That is, the syntax I think you want is this: example.com/?p=1774 rather than this: example.com/?id=1774 ?p= + a valid ...


2

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 object The actual request where parameters can be accessed. * @return array The menu items contained in that specific menu */ function expose_navigation($request) {...


2

A quick search through the WP-API source revealed where validate_callback is being used: wp-api/lib/infrastructure/class-wp-rest-request.php $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); In this case, $this is an instance of WP_Rest_Request - so there's one. Now, for sanitize_callback: $this->params[ $type ][ $key ] =...


2

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/class-wp-rest-posts-controller.php#L918 they will handle your term with sanitize them into non-negative integer using absint. I hope this help. Here example ...


2

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.


2

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 yourself. In fact, if you build custom endpoints, you'll end up using your own QP_Query loops! The choice is really going to come down to the requirements of your ...


2

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 performance of handling the JSON request is int the same order of the performance of handling a page, every page displayed will require about twice the resources ...


2

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 your blog. For more info, have a look at this blog article.


2

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 users data is released in a GET request. *** It's important to mention that if some data you need is unavailable, you probably need to add those fields to ...


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