WordPress Custom Rest Api – How to get Image Url?

$post->ad_1[0][‘top_image’] will not return you data, because you are not in JS which got response from your REST api which had injected ad_1 value into object which it returns to you. In your PHP code $post is of type WP_Post and it doesn’t have ad_1 in it, that’s why you getting nulls. I don’t know … Read more

Inconsistencies between wp_remote_post and cURL

As discovered above, headers need to be (seems so obvious now) key-value pairs, as opposed to an array of json-style key-values: $headers = array(); $headers[‘Content-Type’] = ‘application/json’; $headers[‘Api-Key’] = ‘{myapikey}’; $headers[‘Siteid’] = ‘99999’; And the body needs to be json so either: ‘body’ => “{\n \”Username\”: \”Siteowner\”,\n \”Password\”: \”apitest1234\”\n}” or ‘body’ => json_encode(array( ‘Username’ => … Read more

REST API custom endpoint to fetch pages and posts not working

First off, there’s a default endpoint for retrieving pages, but I presumed that you intentionally did not use it? Now the issues with your code: That $request->get_params() gets all the parameters and not a single one. So for single parameters, you should use $request->get_param(). $slug = $request->get_params(‘slug’); // incorrect $slug = $request->get_param( ‘slug’ ); // … Read more