I’m trying to insert bulk posts via an external php script:
<?php
require_once '/full/path/to/wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
$title = "some post title";
$content = "some content";
$tags= "tag1,tag2,tag3";
$user_id = 1;
// Create post object
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => $user_id,
'post_type' => 'post',
'tags_input' => $tags,
);
$id = wp_insert_post($my_post,true);
?>
$id returns 0 and WP_Error is empty.
Post is inserted to DB with right title and content but without tags. It also fails to use wp_insert_terms() to insert tags or other custom taxonomies.
Did i miss a file to include or is there something i didn’t set right to work functions properly?
you don’t need to load taxonomy.php.. this functionality is handled by wp-load.php
also i would suggest that you put this on first position in your file:
than you can use wp_insert_post() to add the post.. but to add the tags or category and so on you need to use
or
with your recieved $id from wp_insert_post.
for more informations check this: https://wordpress.stackexchange.com/questions/18236/attaching-taxonomy-data-to-post-with-wp-insert-post
Please include the wordpress database files first.
and use the following code to insert post dynamically from the external script.
Refer the tutorial that explains how to create and update wordpress post programmatically.
http://www.pearlbells.co.uk/insert-udpate-wordpress-post-programmatically/