Create Pages from Database

by QUE   Last Updated April 15, 2019 11:08 AM

i've recently decided to create a website with wordpress.

My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.

But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.

Is there some way to dynamically create a page based of a template after the user searched for it?

Answers 1

There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.

Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)

There's a little more information on setting up the redirects in this answer of mine.

Alexander Holsgrove
Alexander Holsgrove
April 15, 2019 10:30 AM

Related Questions

Custom post type with two templates

Updated April 25, 2016 08:03 AM

get_permalink() of page the enclosing page not posts

Updated November 22, 2017 22:08 PM