For our articles on our WordPress site, we would like to display article analytics that are collected weekly for each manuscript. We have these native custom fields for each post:
That data (which is coming from different sources) is being collected for each of our articles weekly into a CSV file. I'd like to run some sort of script each week that will take that data and update the native fields in the Wordpress database (in each post) with the data coming from that CSV file.
Is there a means of writing a script that can do such a thing?
For our articles on our WordPress site, we would like to display article analytics that are collected weekly for each manuscript. We have these native custom fields for each post:
That data (which is coming from different sources) is being collected for each of our articles weekly into a CSV file. I'd like to run some sort of script each week that will take that data and update the native fields in the Wordpress database (in each post) with the data coming from that CSV file.
Is there a means of writing a script that can do such a thing?
You can use PHP's fgetcsv()
or str_getcsv()
function to parse the uploaded CSV file. Your CSV will need to include a column with the Post's ID as well as the columns matching up to your custom field names. Loop through the CSV and for each line update the custom fields for that post using update_post_meta()
http://php.net/manual/en/function.fgetcsv.php
http://php.net/manual/en/function.str-getcsv.php
http://codex.wordpress.org/Function_Reference/update_post_meta