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);
$folder="wp-content/themes/bootstrap/library/";
$file_name = date('Y-m-d') . '.json';
file_put_contents($folder.$file_name, $data);
}
add_action( 'save_post', 'export_posts_in_json' );
Related Posts:
- How can I export post data in xml format?
- How to loop through JSON data in wordpress WP REST API
- WP API V2 returning Invalid User ID
- How can I get an XML export of my 1K+ posts WordPress instance?
- Export User Info to CSV from Front End
- Passing JSON data from WP Query into AJAX causing NULL errors
- Create a new user using WP REST API and declare meta object
- TCPDF get_post_meta outside the loop
- How Do I Add User Custom Field to REST API Response?
- API JSON Data in WordPress
- fetch_feed: retrieve entries in the appearing order, not chronologically
- Gutenberg custom block using only register_block_type() and HTML
- how to decode % in app [closed]
- Export WordPress Table to CSV from page
- Upload a json file in php [closed]
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- How to send user data in json format to another server when user register on wordpress site in PHP
- Create dynamic pages from external JSON data without storing in Database?
- Parsing php string in jquery [closed]
- Vagrantpress + composer
- woocommerce registration form with klaviyo(don’t work with current user)
- wp_remote_get adding backslashes
- Creating a Multi-Level Associative Object Using AJAX
- Fetch post block/field data as JSON with WordPress API
- How to retrieve current wordpress profile page URL?
- wp_enqueue_script seperately for each shortcode
- database sent to a JSON file
- Input data from email form not going to JSON file
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- Fetching instagram api not working on wordpress
- JSON REST API WordPress only showing first 10 categories
- entire JS folder not loading in a WP theme
- Retrieve Json data and create multiple pages with it
- How to clone all WordPress Rest API end points
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- Custom CSV exporter – Cannot modify header information – headers
- Sending simple variable on single page to WP JSON
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Issue with json decode in WordPress – value is not returning consistently
- Export WordPress User Meta to CSV/Excel
- How does one make a URL return dynamic JSON with custom Content Type?
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Need help to create WordPress page that decodes a text file and publishes it in JSON format
- wp_send_json erase last value
- Complex PHP for json_encode > how to handle/output right?
- Can’t get_users info by using json_encode
- How can I export data without using any import/export plugin
- AJAX Filter WHILE Loop not working WordPress
- I want to use wordpress database in android app using json encode?
- Result from wp_send_json adds line feed
- Setting pages for posts
- Search in particular category in wordpress
- How to export database correctly for local to online
- WordPress format json in postmeta table
- How to post data to a word press site in case of a mobile app
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- I am unable to fetch json data from wp_db
- JSON Object Value Show Undefine
- Force array to be a string [closed]
- get_body_params() is always empty in POST request
- How to enqueue structured data as file – jsonld file seems not to work
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- REST API custom endpoints for metaboxes
- WordPress Register Block with metadata
- Disable Attachment Pages Completely
- Get meta_id along with meta_key and meta_value
- Using PHP to toggle stylesheet and header image, set in cookie
- Crop image from get_theme_mod Customizer field
- How can I get content inside one shortcode to another shortcode?
- wp_loaded hook block script enquequing
- Insert a button on a page with random number generation
- Trying to remove post thumbnail with plugin
- How to find error in my code when the error message is pointing to WP core file?
- Hooking into ‘authenticate’ causes login to submit on page load
- Issues getting PHP to display in category pages
- Upload multiple images to a Woocomerce product
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Exclude category
- WordPress wp_add_inline_style unable to give hex colors?
- How to append to an array and return the results in a filter?
- Generating rel=”prev” and rel=”next” using filters
- Shortcode function doesnt work without caption
- Fatal errors to undefined function in theme 404.php file [closed]
- making php value numeric
- the_meta – no get_the_meta query?
- WordPress: Displaying all the post tags from within a specific taxonomy’s term
- how to insert content into my taxonomy
- update_term_meta() only updating once on certain meta keys
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Using a new WP_Query inside the loop
- wp_ajax_ 400 Bad Request
- WordPress Ajax filter: Create two loops for different output styles?
- How to display sticky post always at the top (before regular post) in wordpress?
- Showing wordpress latest post thumbnails in slider with auto increment
- My function echos only “array”
- Trying to fix multiple category drop down
- How can I execute $string = if();? [closed]
- Infinite Scroll Plugin: How to first show 6 posts and then 2 posts thereafter with Infinite Scroll Plugin?
- WordPress online courses system
- Displaying generated HTML within a WordPress site