Have Wordpress generate a JSON of the content

admin2025-06-02  2

This particular project is huge, both in data and in user access (personaly I wouldn't use WP but the client wants to).

The problem is, I don't want the front-end to constantly access the database, so is there a way to make WordPress generate a JSON that I can use in the front-end?

I found one called WORDPRESS JSON API, but it doesn't seems to do this, it still access the DB on each request.

This particular project is huge, both in data and in user access (personaly I wouldn't use WP but the client wants to).

The problem is, I don't want the front-end to constantly access the database, so is there a way to make WordPress generate a JSON that I can use in the front-end?

I found one called WORDPRESS JSON API, but it doesn't seems to do this, it still access the DB on each request.

Share Improve this question edited Jul 20, 2016 at 5:33 Pieter Goosen 55.5k23 gold badges117 silver badges211 bronze badges asked Jul 19, 2016 at 17:46 N. Reek.N. Reek. 131 silver badge4 bronze badges 3
  • Build an associative array of the data you want on the server, json_encode() it, deliver it to the browser. I really don't see the "problem" you describe though - this is what a database is meant to do. Sticking what could amount to tens to hundreds of megabytes of data into a massive JSON structure in browser memory seems like a bizarre premature "optimization". – bosco Commented Jul 19, 2016 at 18:26
  • I don't think you got the way I want these JSONs structured. They wouldn't be a copy of the DB. The result would be hundreds of megabytes in memory. That's absolutely NOT the case. What I need is something like a cache. But I imagined there wouldn't be anything like this in WP. The current website of this client I developed with JSONs like I described. They were a target of several DDoS attacks and never went down. That's why I can't use DB in the front-end. For the new one i think I'll need to create an intermediate tool to treat the DB and create these JSONs. – N. Reek. Commented Jul 19, 2016 at 19:12
  • 1 yes bias against wordpress is the "thing" in technical circle, if only the people that spread the bias have spent the same amount of time learning it, they might have stopped. Your concerens are a solved thing in the community for years (8 years? more?) now.. Actually the solution is so good (enough) that now when the time is to move on into dedicate caching software the community is stuck with the plugin. But if you are starting from scratch, solving caching in app layer is just wrong, use varnish or webserver caching for that. – Mark Kaplun Commented Jul 20, 2016 at 4:27
Add a comment  | 

3 Answers 3

Reset to default 2

After pondering your question some I am guessing you mean to generate actual physical JSON file in filesystem to use as data source? That would certainly be unorthodox in WP development.

Typically in WP you try to minimize disk access, since it is more likely to be a bottleneck in general. Doing file writes is quite inconvenient in WP extension meant for public distribution, but in private of specific server you could generate and dump JSON into a file rather trivially.

For a more "WordPress way" of doing things you might want to look into persistent Object Cache. WP can be made to use persistent memory cache (such as APC, Memcache, Redis, etc), which both greatly increases its general performance and makes it possible to cache data there via WP APIs.

If you're looking to create a JSON feed from your WordPress site, you should almost certainly be using the REST-API plugin. It's robust, well-documented, and slated for inclusion in WordPress core at some point in the future.

There is a caching plugin available for the REST-API that will cache any JSON output to disk for future requests. Disk caching in WordPress decreases access times by a factor of 10x in my experience, and is worth looking into.

Wordpress REST API is in-built and working already in newer versions of Wordpress.

https://www.codeinwp/blog/wordpress-rest-api/

To access the WordPress REST API, you’ll need to start with the following route:

yoursite/wp-json/wp/v2

or

yoursite/?rest_route=/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748816410a313962.html

最新回复(0)