Script updating post field for large number of posts
-
Hello guys,
I need to automatically update the value of a specific field on ALL posts from a certain Pod via a Bash script (more on that later).
Example: Every Monday run (via cron) the BASH script to update the “price” field for ALL posts in the Pod “Equipment”.
I’d like to use the content of another field as an input value for a variable in the BASH script.
I believe “wp_update_post” is the way to go to update already populated fields on existing posts, but I have ZERO experience with php programming and I spent over 300hrs creating & populating hundreds of posts so obviously I am scared to screw up everything (I do have DB backups but….)
How would you go about doing this?
This is roughly how I see things:
Pod=Equipment Post 1210 field('EquipmentID')='52625B4' field('Price')='212.50' Post 9568 field('EquipmentID')='13295C6' field('Price')='76.50' Post 9563 field('EquipmentID')='98765H3' field('Price')='1236.74' ...
“Pseudocode”
for each posts in "Equipment" Pods 1. Retrieve string from EquipmentID field 2. Call & run external BASH script with the value retrieved in No. 1 3. Grab the value returned by the BASH script 4. Overwrite the value in the Price field with the value from no. 3 end
About the BASH script: I selected BASH because 1. I run Linux (Rocky Linux), and 2. I am using CURL to retrieve contents from the internet, and use “pup” & “jq” to parse HTML data into something usable… As I said I am absolutely useless in php but I dont see how performing the work would be possible other than using BASH.. I could be wrong…
Moreover, I want to run and update the fields on a periodic basis (lets say once per week or month). Again, cron makes it so easy….
Looking forward to replies and suggestions! I am curious to see what the experienced folks have to say about this!
Thanks!
- The topic ‘Script updating post field for large number of posts’ is closed to new replies.