0

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?

  • What about an hourly cron job that tests for changes, converts and stores the field values for the display plugin? If freshness is more critical, hook your script to something like save_post so everytime a post is updated the process is triggered. codex.wordpress.org/Plugin_API/Action_Reference/save_post – jdm2112 May 5 '17 at 1:12
  • thanks - yes the hourly rate would not be enough it would have to be every minute or something like that really. The site would not have save_post happening very often it's not that type of site I think almost all the administration will be via CSV import but I'm sure wp-all import must trigger something similar with every import so I could use that for the csv imports in combination with save_post for the wordpress edits - I still don't know exactly how but you've got me thinning - thanks – byronyasgur May 5 '17 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.