posts – WP Remote Request not returning all of content via request

Question

EDIT: I think I discovered the issue, the endpoint is truncating the content response, does anyone know how to send over all of the data without it being truncated?


So I stumbled across some inconsistencies when requesting posts from one of our websites and not being able to pull in ALL of the content for a specific post.

Explanation:

  1. Let’s say that we have our REST API endpoint from the website where the posts live: https://test.com/wp-json/wp/v2/posts.

  2. When I decode and get the response, I only get partial items included inside the response, such as this:

Website hosts this in Text Gutenberg blocks:

Banking on a Lifestyle: three ways to communicate the shift

In recent years, banks have begun accompanying us into areas of our lives previously uncharted by the financial services sector. Going for a coffee with a friend? Make sure you get cashback rewards with your bank. Hooked on a new TV series? Get some free months of streaming with your bank. Booking a holiday? Get cheaper prices if you book with your bank.

FinTechs in particular are enabling people to bank based on their lifestyles. Challengers have clocked on to the fact that university students, for example, don’t want good quality pension plans yet…they want 50% off pizza. They’ve adopted a customer-centric model that allows different people to make more of their money at different stages of their lives.

Lifestyle banking is making waves in the industry: legacy banks now realise they need to get a move on and learn from this approach, while FinTechs need to up their game in the face of rising competition.

So how should banks and FinTechs alike communicate this lifestyle-led approach? Particularly when we’ve seen some real bloopers in this area recently…

What I get over the REST API:

    ["content"]=>
    object(stdClass)#941 (2) {
      ["rendered"]=>
      string(731) "<div class="container">
<div class="row">
<div class="col-md-10 col-lg-9 offset-lg-1">
<p>Banking on a Lifestyle: three ways to communicate the shift In recent years, banks have begun accompanying us into areas of our lives previously uncharted by the financial services sector. Going for a coffee with a friend? Make sure you get cashback rewards with your bank. Hooked on a new TV series? Get some […]</p>
</p></div>
</p></div>
</p></div>
"
      ["protected"]=>
      bool(false)
    }
  • Does anyone know what causes partial data to come back only?
  • Is it an issue because the website is using gutenberg blocks, which is the new editor?

I’d like to retrieve the FULL content of the post, this includes any paragraphs, all images inside the post, etc..


I have the following snippet:

$response = wp_remote_request(add_query_arg( [
    'page' => 1,
    'per_page' => 3,
    'post_status' => 'publish',
], 'https://test.com/wp-json/wp/v2/posts'));
try {
    $posts = json_decode(
        wp_remote_retrieve_body($response),
        false,
        512,
        JSON_THROW_ON_ERROR
    );
    if (empty($posts)) {
        return;
    }
} catch (Exception) {
    return;
}

0
Test2 5 months 2022-03-22T13:14:17-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse