Create a plugin to create a new page in wordpress for each time a record is added into the database

I am new to wordpress and would like to get a way forward for a particular problem.

  1. I have a database table A with various columns.
  2. For each record in table A a wordpress page needs to be created in the wordpress database.
  3. The page should be custom designed.
  4. The whole process has to be included in a plugin.
  5. The admin uses the plugin to create pages after database is updated.

Any help would be appreciated.

Regards.

Answer

Points 1 and 2:

Use the wpdb class to read the table. Then use wp_insert_post() to create your page.

Point 3:

WordPress has a Template Hierarchy that allows you to define which theme file to use.

Point 4:

Read the article on Writing a Plugin and add your code in it.

Point 5:

Choose a way to mark which was the last item that was processed, You can for example, save the index of the last article you processed assuming the index increments after each new record. You can even automate the job using wp_cron.

Attribution
Source : Link , Question Author : Manjeet Panda , Answer Author : RRikesh

Leave a Comment