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
- Ajax contact form widget plugin data not insert in database
- How to display the “ratingValue” and “ratingCount” values generated by the KK Star Ratings plugin into my page’s recipe ld+json schema
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- Theme is Causing Ajax Conflicts for a plugin I cant identify it
- Why WordPress plugin url ajax doesn’t work?
- wordpress json api not working
- wordpress, search form using ajax
- How to use JSON data from URL into table on my wordpress website
- jquery not calling php function
- Search for categories
- Admin accounts unable to see plugins from external IP
- How to allow an editor to edit all WordPress blog posts but have the last say as administrator?
- Plugin dependencies: show notice like theme plugins dependencies
- Best place for if/else piece of code related to custom plugin?
- 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]
- Ajax call returning 0
- How to set add question capability for author role in wp pro quiz plugin
- Ajax with plugins returns 0
- WordPress + JavaScipt + AJAX + MySQL: insert query for form
- Blog titles from WP blog on plain html site?
- Ajax fail and get 504 error
- Ajax Search Lite: Customize Autoscroll
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- WordPress Integration with Google Groups
- Best place to load wp_ajax_the_ajax_hook action in plugin
- jQuery.post not working within shortcode – WordPress Ajax
- Create tabs in admin options page from custom post type loop
- How to load wp_editor via AJAX
- How can I inject options into an select tag inside the widget form?
- Init plugin again after ajax call finish
- do_action() hook into load-(page)
- Display wordpress post’s in popup?
- Using AJAX to generate front end / viewer end pages
- Using color picker in plugin, does input attribute order matter?
- How to handle cookies from a WordPress plugin on a cached page?
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- How to change the name of the “edit my profile” link in the WordPress admin backend
- wordpress file upload with ajax when site is ajaxyfi
- Post Comments with Ajax in WordPress
- AJAX search as you type? [duplicate]
- Sync User to cPanel webmail?
- WordPress api call using wp-ajax returns error 400
- Adding CSS to custom post type admin page causes error
- AJAX call – failling to call do_action
- how to insert data in wordpress table usnig jquery ajax
- Using wpdb without loading all plug-ins via wp-load.php
- What are the Best Practises When Using AJAX in Plugin Development?
- Display Custom Field Value on Admin Page Column
- How to remove/hide Yoast’s “SEO” tab in admin panel?
- Add sub menu page in your plugin
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- What’s causing this error? “Warning: Invalid argument”
- Call plugin with php function
- Render Modula Plugin Shortcode On Ajax Request
- Prevent plugin from intruding on wp-json posts api
- AJAX on Front-End Button Click not working – Custom Plugin
- How to handle WordPress Plugin Front-end AJAX Call [duplicate]
- Move plugin-settings to ‘Settings’-menu in the admin
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- Submit Form data to another page via Ajax (WordPress Way)
- AJAX Load more start with x posts
- Is it safe to use admin-ajax.php in the frontend?
- plugin shortcode not working on ajax request call
- wordpress add_action() issue in ajax call
- WordPress Admin Menu defining function is seperate file
- How to display checked posts on another page over AJAX? (like comparasion style)
- How do I add some javascript validation to the admin interface form’s onsubmit?
- remove all submenus from plugin
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Plugin getting Cannot modify header information errors
- Ajax Plugin Not Echoing Response
- where do I send my ajax calls
- creating a plug in that would tap into save/update action of posts [closed]
- Simply poll & Events Calendar plugins clashing
- Ajax save data to database on document ready, no data being saved
- WordPress front end AJAX. Return 0 :?
- How to see which sites use my installed plugins (wordpress multisite)
- WordPress Ajax code is not Working
- Using WordPress to build membership Page
- don’t call ajax if not plugin page
- How to get specific string/value from an array? php [closed]
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error
- 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?