Here I assume your json is an array of object where properties are named like wp_insert_post
arguments: ‘post_title’, ‘post_content’ and so on.
function process_ajax() {
if ( ! isset($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], 'mynonce') )
die('error on checking nonce');
if ( ! isset($_POST['filepath']) die('no file given');
if ( ! file_exists($_POST['filepath']) ) die('invalid file given');
$posts = json_decode( file_get_contents($_POST['filepath']) );
$done = 0;
if ($posts) {
foreach ( $posts as $post) {
$post = (array)$post;
if ( isset($post['ID']) ) unset($post['ID']);
if ( wp_insert_post($post) ) $done++;
}
$str = "Successfully insert " . $done . "posts, ";
$str .= ( count($posts) - $done ) . ' failed.'
die($str);
} else {
die('File contains not valid Json.');
}
}
Related Posts:
- How can I make an Ajax login form work with FORCE_SSL_ADMIN enabled?
- Add image to post from external URL
- What’s the point of using WordPress’s built in admin-ajax.php?
- AJAX in plugin wp_send_json() sending html
- Admin AJAX doesn’t work in plugin admin page – Even though code is copied verbatim from WordPress Codex
- Adding inside wp-plugin jQuery script that receives JSON-formatted data, generated by php-function inside this plugin
- Remove value from array within post meta ajax admin
- Call Ajax URL in Plugin
- Ajax request sends url rather than data
- In a plugin, How to update a json file using ajax
- How to use Datatable with Ajax when creating plugin on WordPress?
- Ajax specific template not loading in replacement of index.php
- admin panel save option with ajax
- Plugin Admin Page Ajax-Admin call returning 0, URL set correctly. Implemented localized scripts but did not fix it
- WP Rest API: details of latest post including featured media url in one request?
- How to load wp_editor via AJAX
- How to check if user is in back end?
- How do i know the current post type when on post.php in admin?
- Plugin or mod for wordpress to make content publication SUPER easy
- How do I only load a plugin js on it’s settings pages?
- How can I pass a variable to wp_ajax action?
- How to add a help tab to all admin pages – including plugin pages
- How to develop a community feature in the dashboard for multiauthor site
- How to add a sub menu with AJAX?
- Execute a function using ajax
- Problem running Ajax in WordPress
- Filter or action hook to insert content on admin pages before tag
- How to edit/delete single row items in a table on my own menu page
- How can I reuse the WordPress search form for a custom plugin / widget?
- AJAX image upload with a upload progress bar using media_handle_upload
- jQuery Plugin to use WordPress functions in AJAX request
- Change wording of admin menu item?
- Set of plugins to control the Admin UI
- Which plugin will let me decide what users have access to on their side bar in wp-admin?
- What would be the advantages/disadvantages of remote plugin installation?
- Simple ajax call not working in wordpress plugin
- Remove Duplicator plugin from admin menu if not an administrator
- Doubt using $wpbd->get_col for a single column
- Add a custom form on the post-new.php admin page
- How to put JQuery/Ajax inside shortcode?
- __callStatic method handler passed to add_action causes bug in PHP
- How to display the “ratingValue” and “ratingCount” values generated by the KK Star Ratings plugin into my page’s recipe ld+json schema
- How to use JSON data from URL into table on my wordpress website
- Admin accounts unable to see plugins from external IP
- Making sure that a plugin’s scripts and stylesheets are included for dynamicaly loaded content
- WordPress wp-admin/network/plugin-install
- how to access all user dashboard on fronted page [closed]
- How to set add question capability for author role in wp pro quiz plugin
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- Using AJAX to generate front end / viewer end pages
- Post Comments with Ajax in WordPress
- What’s causing this error? “Warning: Invalid argument”
- Render Modula Plugin Shortcode On Ajax Request
- AJAX Load more start with x posts
- Plugin getting Cannot modify header information errors
- WordPress front end AJAX. Return 0 :?
- How to use the CSS of the WordPress core in the development of my administration page?
- How to do the simplest possible frontend ajax call from a plugin?
- in source code but I can’t find it in files or plugins
- Updating WordPress plugin admin panel footer text
- Asynchronous request in wordpress
- getting notifications about updates only in the “core” page
- How do I localize admin-ajax.php that is used in Ajax Load More – Infinite Scroll?
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- Loading by Ajax a plugin that also uses Ajax
- Insert a Woocomerce product in specific product category
- How to call php file in theme directory from plugin
- Upload Javascript and json webpage to wordpress
- How can I adjust my function so the page editor still loads in the backend?
- wp_insert_post not inserting post from XML
- Admin Custom Plugin List Files in admin Table
- Error datatable whit ajax
- Facing Problem with admin-ajax.php URL – Getting 404 with AJAX call
- WP Ajax DB issues
- jQuery Ajax not loading page with ACF fields
- WordPress output data to another website and pull data
- How achive serving multiple concurrent Ajax / Rest calls in plugin?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Overwriting Plugin’s Ajax callback function from theme
- API page return Header 500 but Work
- Get content and send to 3rd party
- Populate select option with JSON file
- WordPress update plugin through Dashboard/Plugins displaying error
- Choose default template for a page with code
- Is it possible to get a shortcode generated by a plugin, then, using a function, create a new post using that shortcode?
- display user input using ajax in wordpress
- Getting 404 page not found error while trying to access add new plugin / themes
- Ajax, jQuery and WordPress
- Hyperlink to execute PHP
- How to get site homepage from plugin?
- Contact Form loaded with Ajax
- How to load a plugin when doing an Ajax call? [duplicate]
- WordPress plugin ajax post parameter
- Capturing POST data
- Pulling Advanced Custom Fields from other pages
- What would cause edit buttons for plugins to disappear?
- Response from Php File to Ajax is not getting sent
- How to make a rest style plugin?
- WordPress portfolio pagination on home page
- wordpress Ajax success doesn’t return the value