Support » Plugin: WP REST Cache » Support for the _embed query param

  • Resolved davidrouyer

    (@davidrouyer)


    Hi guys,

    I’m currently trying to use the plugin but doesn’t seem to support the _embed query parameter.

    The response of https://wp.hopfab.com/wp-json/wp/v2/posts looks exactly the same as the response of https://wp.hopfab.com/wp-json/wp/v2/posts?_embed.

    “id”: 1,
    “date”: “”,
    “date_gmt”: “”,
    “guid”: { … },
    “modified”: “”,
    “modified_gmt”: “”,
    “slug”: “”,
    “status”: “publish”,
    “type”: “post”,
    “link”: “”,
    “title”: { … },
    “content”: { … },
    “excerpt”: { … },
    “author”: 1,
    “featured_media”: 1,
    “comment_status”: “open”,
    “ping_status”: “open”,
    “sticky”: false,
    “template”: “”,
    “format”: “standard”,
    “meta”: { … },
    “categories”: [],
    “tags”: [],
    “_links”: { … },
    “_embedded”: { … }

    The _embedded property is missing

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Acato

    (@acato)

    Hi @davidrouyer

    Thank you for using our plugin!

    The plugin is doing nothing to prevent the _embed query parameter from working. As a matter of fact, we ourselves are using this query parameter quite a lot in combination with our plugin. I just tested it on one of our headless sites and it is working correctly and also being cached correctly.
    I visited the urls you provided, but it appears you no longer have the plugin activated, since I don’t see the X-WP-Cached-Call response header.

    Thread Starter davidrouyer

    (@davidrouyer)

    Sorry @acato, I desactivated it on my production environment.

    It looks like most of the time it works, but sometimes it doesn’t … You can take a look at my staging environment and this post https://staging.wp.hopfab.com/wp-json/wp/v2/projects?slug=agencement-surmesure-bureaux-alter-solution&_embed

    Thread Starter davidrouyer

    (@davidrouyer)

    Plugin Author Acato

    (@acato)

    Hi @davidrouyer

    It appears that your setup doesn’t always correctly include the _embedded. If I take your example: https://staging.wp.hopfab.com/wp-json/wp/v2/projects?slug=agencement-surmesure-bureaux-alter-solution&_embed and add &skip_cache=1 to (that will force it to NOT use cache) I also don’t see the _embedded. So if it isn’t generated it can not be cached 🙂

    As I said, the plugin isn’t doing anything to prevent the _embed parameter to work. As a matter of fact the very simple explanation of how it does the caching is:
    Is there a cache available?
    – Yes? > Return cache
    – No? > Let WordPress process the request as it would normally do (including handling all query parameters) and cache the result.
    So the first time the cache is created it is all handled by WordPress, the plugin doesn’t do anything to the results of the call.

    Thread Starter davidrouyer

    (@davidrouyer)

    I tried with and without &skip_cache=1 and you’re right, the response is the same. But my point is it always works when I disable the plugin. If I disable the plugin, https://staging.wp.hopfab.com/wp-json/wp/v2/projects?slug=agencement-surmesure-bureaux-alter-solution&_embed returns correctly the _embedded part.

    It’s difficult to spot since it breaks randomly on endpoints when I disable/enable the plugin.

    Plugin Author Acato

    (@acato)

    Hi @davidrouyer

    Sorry to ask, but if it breaks randomly how can you be sure it is because of the plugin?

    I have searched through the WordPress core, specifically the part where the _embed parameter is processed. But unfortunately I can not find any clue as to why our plugin would break this functionality. As a matter of fact I have tried to reproduce it on my local test-environment, but whatever I do (with or without the plugin activated) it simply always works. Especially the randomness of the issue, makes it really hard for me to explain.
    I would like to help you debug this issue, but at this point I really need more information: what plugins do you have installed (and which are activated)? What theme? How do you make the call to the REST API? Are you sending any extra headers?

    Thread Starter davidrouyer

    (@davidrouyer)

    I never have such an issue without it, this is why I report it 🙂

    I’m currently running WordPress 5.2.2 on PHP 7.3.

    I only have Yoast SEO 11.5 and ACF Pro 5.8.1 and custom plugins I’ve written myself to add custom types to WordPress.

    I’ll try to debug the issue myself this week-end en report back to you.

    Plugin Author Acato

    (@acato)

    Hi @davidrouyer

    Well that aren’t much plugins, so little change any of the other plugins is causing this. I will try and debug it myself too, but unfortunately that will be somewhere next week. So please let me know if you find something, so we can see if we can deploy a fix for it 🙂

    Thread Starter davidrouyer

    (@davidrouyer)

    I previously installed W3 Total Cache before installing WP REST Cache

    It automatically added define(‘WP_CACHE’, true); to the wp-config.php file.

    Then I deactivated W3 Total Cache to install WP REST Cache but the define(‘WP_CACHE’, true); remained.

    I deleted W3 Total Cache, removed that variable and it seems to work fine now.

    Thread Starter davidrouyer

    (@davidrouyer)

    It doesn’t fix my problem :/

    Thread Starter davidrouyer

    (@davidrouyer)

    I fixed my problem. It was due to a misconfiguration. I use WordPress on top of Kubernetes with the Bitnami Docker image and it works differently from a normal installation.

    Plugin Author Acato

    (@acato)

    Hi @davidrouyer

    Thank you for letting us know you solved it! And please let us know if we can be of any more assistance.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Support for the _embed query param’ is closed to new replies.