I’m using MongoDB to store separate data for a WordPress website and need to be able to create pages with the data from MongoDB rather than from manually created pages in the dashboard. I’ve searched all over for this and can’t seem to find anything for creating pages in the backend.

Is this even possible and if so, does somebody know a good starting point or way to do it?

Any information would be great.

3 Answers
3

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *