Slow REST API calls on self-hosted WordPress [closed]
Slow REST API calls on self-hosted WordPress [closed]
Slow REST API calls on self-hosted WordPress [closed]
You have rewrite_rules in wp_options table. From there your app can have idea of what the wordpress is going to rewrite in future and how it is going to rewrite after index.php. You can use regex in JS with wp_options data to customise your app response. UPDATE Here is block of code I needed to … Read more
Try the suggestion below: This assumes the <figure> element holding an image has a data-display-alignment attribute to match the alignment class applied attached that is somehow surfaced as a parameter in the wp_calculate_image_sizes hook: /** * Add custom image sizes attribute to enhance responsive image functionality * for content images. * * @param string $sizes … Read more
This is an old question, but the current REST API indicates that the X-WP-NONCE header should be set via the beforeSend callback. The following is directly from the REST API docs. .ajax( { url: wpApiSettings.root + ‘wp/v2/posts/1’, method: ‘POST’, beforeSend: function ( xhr ) { xhr.setRequestHeader( ‘X-WP-Nonce’, wpApiSettings.nonce ); }, data:{ ‘title’ : ‘Hello Moon’ … Read more
Unfortunately, this functionality is not natively supported out of the box. In detail, the problem is that most post types including page use the base WP_REST_Posts_Controller which maps the slug parameter to the post_name__in WP_Query argument, which does not facilitate resolving hierarchical slugs. The pagename query variable does, however – but only one per query, … Read more
On the initial issues, are you positive the plugin is registering the fields to be made available to the api? the register_meta needs show_in_rest => true assigned. Also, the CPT needs custom-fields in its supports array, ‘supports’ => array(‘title’,’editor’,’thumbnail’,’custom-fields’) for that to made available when accessing the CPTs api endpoint. I cover that (with links, … Read more
Try This First: Your Problem Might Be DNS In my testing this is a problem with DNS resolving. In my case it’s because the DNS filter/cache I run on my local network wasn’t responding to requests. After restarting the service on the DNS server my requests got through quickly & easily. I would suggest checking … Read more
It looks like you’re missing the nonce part, as explained in the Authentication chapter, in the REST API Handbook: Cookie authentication is the basic authentication method included with WordPress. When you log in to your dashboard, this sets up the cookies correctly for you, so plugin and theme developers need only to have a logged-in … Read more
You can modifiy REST API responses in themes functions.php like this. 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( $object->id ), ‘medium’ ); $medium_url = $medium[‘0’]; $large = wp_get_attachment_image_src( … Read more
The issue was because I wasn’t generating and sending a nonce value with the request. In order to generate a nonce value. Localize the value of a wp_create_nonce(‘wp_rest’) function call. wp_localize_script(‘application’, ‘api’, array( ‘root’ => esc_url_raw(rest_url()), ‘nonce’ => wp_create_nonce(‘wp_rest’) )); This will then be accessible to the window object of the browser which can be … Read more