New answers tagged

0

it's file_put_contents which saves the data then it have to be in the hook and not in the body of the plugin : function export_posts_in_json () { $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, ); $query = new WP_Query( $args ); ... $data = json_encode($posts)...


2

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 ...


1

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 ...


1

The way I do it. Note there may be a more straightforward way. Step 1 Add a custom query_varlike this to record the redirect from/to variables function my_custom_query_vars($vars){ //this allows you to store custom variables with rediect_from and rediect_to in the url $vars[] = 'redirect_from'; $vars[] = 'redirect_to'; return $vars; } ...


1

There are two aspects here obviously all input should be sanitized JSON is just a wrapper no different then any other type of container which is used to aggregate data for transmission. You almost never sanitize the container as usually in case of an error you will just not be able to extract the data from it, but each piece of data should be sanitized. ...


2

In version 1.1 of the JSON REST API custom post type endpoints have to be registered manually. See: http://wp-api.org/guides/extending.html#registering-your-endpoints In version 2.0 we register endpoints for any custom post types registered with the show_in_rest property set to true. Documentation on how to do this: http://v2.wp-api.org/extending/custom-...


1

Take a look at a plugin called Better REST API Featured Image. It adds the featured image URL to the original API response.



Top 50 recent answers are included