How and when would I implement some code which would take data from one part of the Db and put it in another?

My situation is that I have a display plugin I want to use which can read and display information from custom fields but the information in the custom field is not in the correct format so the plugin’s output for that section will not be useful.

(The information in the database can’t be changed easily because it’s a large product catalog managed via CSV import)

I have considered a plan to ( for each custom post)

  1. Take the information from the various custom fields
  2. Process it into a suitable format for the plugin to display
  3. Store it in a new custom field in the Db (ready for use by the plugin)

I think I probably know how to do the above or could figure it out, that’s not the issue at the moment


The problem is that I am not sure when and by what method to run the eventual script.

The information in the various custom fields will be changing regularly ( with every CSV import/update ) and I want to keep my new custom field data up to date with it.

I have considered the following options for running the script …

  • Have the script run automatically when the file is imported
  • A button to press from the dashboard which would run the script to manipulate
    the data
  • A Cron job.

However…

  • The problem with running the script on the CSV import is that it doesn’t cover a situation where the data was edited via the WordPress interface
  • The problem with the button is that it’s manual and it could be forgotten.
  • I don’t know much about crons and running a script like this but there are about 2000 ( custom ) post entries and I would rather they updated straight away so I can’t imagine that being good for performance if it was set to run every minute or something — or maybe that’s OK?

But maybe there’s a “WordPress Way” I don’t know about – in this scenario I’d imagine WordPress “noticing” if something had been changed in any of those custom fields; and then if it has been then it would run my script to aggregate the data for the custom field that the plugin would read. Is anything like this possible or if not how would be best to achieve this?

Read more here: How and when would I implement some code which would take data from one part of the Db and put it in another?

Leave a Reply

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