Create WordPress pages with PHP

You can programmatically create posts and pages using wp_insert_post or insert content using WXR files via WordPress’s import feature.

To use wp_insert_post see the documentation here: http://codex.wordpress.org/Function_Reference/wp_insert_post

A simple example:

 $my_post = array(
          'post_title'    => 'hello',
          'post_content'  => 'This is my post.',
          'post_status'   => 'publish',
          'post_author'   => 1,
          'post_category' => array(1),
          'post_type'     => 'page'
          );

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

BUT you are probably better off using WordPress’s import functionality. WordPress uses WXR files which stands for WordPress Extended Rss ( if you know XML you will see it looks similar).

So it would be better for you to parse you mongo content into a WXR file and then just import it into WordPress.

A detailed write up on WXR: http://devtidbits.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/

Also you can just add some dummy content to WP and export it and view the WXR file to see what format you should follow.

Leave a Comment