php - Inserting Wordpress Post via External Script -
i'm trying insert bulk posts via 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 , wp_error empty. post inserted db right title , content without tags. fails use wp_insert_terms() insert tags or other custom taxonomies.
did miss file include or there didn't set right work functions properly?
you don't need load taxonomy.php.. functionality handled wp-load.php
also suggest put on first position in file:
define( 'wp_use_themes', false );
than can use wp_insert_post() add post.. add tags or category , on need use
wp_set_post_terms()
or
wp_set_object_terms()
with recieved $id wp_insert_post.
for more informations check this: https://wordpress.stackexchange.com/questions/18236/attaching-taxonomy-data-to-post-with-wp-insert-post
Comments
Post a Comment