How to add WP API and JS featured image attachment

I manage to solved it by adding this code (at the bottom) to the YOUR BLOG THEMES my path : wp-content/themes/twentysixteen/function.php: function ws_register_images_field() { register_rest_field( ‘post’, ‘images’, array( ‘get_callback’ => ‘ws_get_images_urls’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘ws_register_images_field’ ); function ws_get_images_urls( $object, $field_name, $request ) { $medium = wp_get_attachment_image_src( get_post_thumbnail_id( … Read more

WP Rest API get page from path

It is usually easier for me to decide how the front end should behave, and then determine how to get the appropriate data. So, in your example, services would be a module with some functionality, and then service-a would be the slug. However, if you only care about the URL looking the same you can … Read more

PHP Fatal error: Cannot use object of type WP_REST_Response as array in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Nobody pointed out I was using ‘$data’ incorrectly. function dept_cat_api( $request ) { $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘crosspost’, ‘field’ => ‘slug’, ‘terms’ => array( $request[‘dept’] ), ), array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( $request[‘cat’] ), ), ), ); $posts = … Read more

Post body not working with wp_remote_post()

You’re setting the Content-Type header to application/json and wp_remote_post() doesn’t intelligently JSON-encode the request data (the body array), so you should manually do it. So for example: ‘body’ => json_encode( array( ‘Username’ => ‘myusername’, ‘Password’ => ‘mypassword’ ) )

Backbone.js and WP API

I haven’t used the WP-API/JSON REST client plugin so far, but this is what I can see in source: The ~/js/models.js is the entry point for all requests, it seems. And every of the wp.api.models (to name a few: Page, Post, Media, Revision, etc.) is just an extension of Backbone.Model. And looking into the actual … Read more

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 items to be returned in result set.’ ), ‘type’ => ‘integer’, ‘default’ => 10, ‘minimum’ => 1, ‘maximum’ => 100, ‘sanitize_callback’ => ‘absint’, ‘validate_callback’ => ‘rest_validate_request_arg’, ), … Read more

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 ship with any authentication scheme other than the cookie/nonce option (which doesn’t work with external apps, as you describe). There are plugins for authenticating … Read more

Inserting custom post meta value using WP-REST API

Well, there is a way to update post meta. You have to add the update_callback when registering rest field. See the example below: function rest_api_player_meta() { register_rest_field(‘sp_player’, ‘player_meta’, array( ‘get_callback’ => ‘get_player_meta’, ‘update_callback’ => ‘update_player_meta’, ‘schema’ => null, ) ); } function get_player_meta($object) { $postId = $object[‘id’]; return get_post_meta($postId); } function update_player_meta($meta, $post) { $postId … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)