I'm currently working with a WordPress developer for my site and we are attempting to create a WordPress post/page for every item in my database.

There is a search-bar on the homepage and when the user searches for an item they will be brought to a unique page for that item that will allow users to leave comments.

The problem is there are around 10,000 items in the database that need this. The developer is slightly unsure and suggest the use of a script to automatically generate a post or page for each item but he stressed it would decrease site performance.

Is there an easy way to automatically do this while also allowing WordPress style comments for each item?

As it currently stands:

There is one page with the database search bar that will display the info under the search bar once the item is selected. The problem with this is that you will only ever have one set of comments for every single item which I don't want.


What you're asking a too broad to decently fit in WPSE's Q&A format, but I'll try to sketch an approach that could work.

From what I understand you have 10.000 database items that are not WordPress (custom) posts. You still want to present them as WordPress pages and enable comments per item. I'm guessing that your database is not static, so a one-off action to read them into WP is a no go.

So the solution would be to generate a WP post at the moment the database item is first called upon. Sketchily:

  1. Register a custom post type that holds only a unique identifier of your database item (and allows comments).
  2. When a database item is called upon, check its identifier. If there already is a post with this identifier, that's fine, else create one with wp_insert_post
  3. Build a special template for this custom post type that draws more data from your database using the unique idenfitifier and retrieves comments from the WP database.

Beware that whatever your approach is, you will be creating dependencies between two databases, which will make future maintenance more difficult.

  • Thank you! This is very useful information and it gave us both more to think about. This sounds like a solid template for a plan to move forward. Sep 29 '16 at 10:08

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.