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.
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_postA simple example:
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.
Why would the type of DB you use have any relevance to the front end of the site? In theory, if you make the required SQL and DB access adaptations, you can run wordpress on MongoDB.
Pages are front end artifact used to manage the generation of content and url resolution and if you don’t want to use them then why are you using wordpress at all?
Everything can be done in wordpress but it doesn’t mean that wordpress is the best option for every task.
First of all, it’s my drawback that, I’m not accustomed to MangoDB, but I think I can answer the context.
To introduce your custom PHP into WordPress pages, a best way is to create a Page Template.
STEP I: Creating your custom template page
Create a new PHP page, totally new one with the following code:
Save the file inside your theme folder with a name you like, i.e.
my-template.php
.Then you can do whatever with PHP & MySQL inside the page template. But to work with MySQL in WordPress, there is a suggested way, and that is $wpdb.So now for a check, just put the basic PHP thing:
echo "Hello World!";
inside the page template.STEP II: Using the template into page
In
/wp-admin
, create a new page, give it a title relevant to the PHP code or function of the page, and right to the editor, choose your template page from the drop down menu, you will find: “My Custom Page” there. Choose the template and save the page.Now view the page and see how you are saying “Hello” to the World!
ANOTHER WAY
Another way is to use PHP within Pages, is to use a plugin like:
To work with the plugin, a tutorial is available here.