REST API: Display Category names in JSON?

For my needs, I customized the wp rest posts callback: function get_all_posts( $data, $post, $context ) { return [ ‘id’ => $data->data[‘id’], ‘date’ => $data->data[‘date’], ‘date_gmt’ => $data->data[‘date_gmt’], ‘modified’ => $data->data[‘modified’], ‘title’ => $data->data[‘title’][‘rendered’], ‘content’ => $data->data[‘content’][‘rendered’], ‘excerpt’ => $data->data[‘excerpt’][‘rendered’], ‘category’ => get_the_category_by_ID( $data->data[‘categories’][0] ), ‘link’ => $data->data[‘link’], ]; } add_filter( ‘rest_prepare_post’, ‘get_all_posts’, 10, 3 … Read more

PHP: authenticate for a REST request?

What do you mean by “external users”? If you only want Users, that are logged into your website, to use the API Endpoint, you can filter the “rest_authentication_errors” like described here Add this to your plugin: add_filter( ‘rest_authentication_errors’, function( $result ) { if ( ! empty( $result ) ) { return $result; } if ( … Read more

body_class REST field in WP-API

get_body_class() relies on $wp_query to do its thing, which is apparently a no-go for the JSON API. I considered creating a global object to hold the body class, and just using that to keep the body_class up to date…but that wouldn’t work without page reloads, and there would be no assurance that the object was … Read more

rest api request including meta_query filter

Maybe not exactly the answer you are looking for, but here it goes…. The rest API as it is implemented in wordpress core is a mockery of how APIs should be designed and the less you use it the better. Obviously it will be just stupid to not use a core API that does exactly … Read more

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