I want to create a php script that reads the rss feed content from another website and then adds those read information into my WordPress website's database so that when you go to my WordPress website you will see those inserted posts via my php code.

The problem is: I want to use built in codes of WordPress for adding new posts and I don’t want to go through writing my own code for inserting data into MySQL.
Is there a fast way?
I want to be able to add these information into WordPress by my php script:

  1. Post content
  2. Post title
  3. Tags
  4. Post categories
  5. Date: for this I want to add the time and date when the new post is inserted into database.
  6. Writer

At the beginning of my php script that I am writing, I first connect to the wordpress's Database using username and password of that database.

Is there a fast way for adding new content by php into wordpress's database? Is there any special function for doing this? And for using that function what should I do in my php script? What should I include in it?


You can use the wp_insert_post function

   $my_post = array(
            'post_title'    => 'Some titles',
            'post_content'  => 'This is my post content',
            'post_status'   => 'publish',
            'post_author'   => 1,
            'post_category' => array(1, 2, 9000)

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.