Use of wp_insert_post and parameters

Question

I’ve JUST started using WordPress..i’m trying to add posts to WordPress using php and i came across this piece of code:

// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );

i understand this is the way to go when creating a post using php..my questions are:

  1. how do we execute the above php script and where do we save it in the WordPress folder?

  2. what does the ‘post_category’ array mean(i’d like to use a category id to add posts to WordPress)?

i’d like to mention that i’ve done some descent searching on the net but the resources i’ve found do not mention how to execute the above script.

0
, user11 4 years 2020-05-28T15:10:20-05:00 0 Answers 87 views 0

Leave an answer

Browse
Browse