First of all, thank you for being part of an impressive community that has helped me out a thousand times before.
In my Wordpress environment (Enfold theme, Woocommerce plugin) I created a system to use a survey as input for instantly to-be-created posts in a front-end website. Answers in the survey are included in automatically generated posts (type 'product') including WooCommerce Custom Attributes.
I wrote custom queries responding to triggers in mySQL - inserting & updating wp_posts, wp_terms, wp_postmeta, wp_term_relationships.
All works fine, except for one thing: WooCommerce custom product attributes are not displayed instantly in dropdown/select filters on the website. However, 'manually' pressing Update on the Wordpress-page does the job.
I'm looking for a way to exactly replicate the 'manually' pressing Update in the Wordpress CMS. So far, the post itself succesfully loads in the website, but its WooCommerce product attributes are not instantiated.
So far, I've tried many workarounds:
- Programmatically setting the status of a post (draft) and changing it instantly to a published post (publish);
- Using the in-built post Scheduling of Wordpress by setting a time on which it should be published;
- Calling wp_update_post;
- Using the Tao Scheduled Updates plugin (https://nl.wordpress.org/plugins/tao-schedule-update/);
- Using the WordPress PostController plugin (https://github.com/HarriBellThomas/Wordpress_PostController)
Still, all the attempts only update the posts in wp_posts, apparently not the underlying relations/custom product attributes.
My only request would be to programatically replicate the clicking on 'Update' in the Wordpress CMS environment. This would help me in automating the process instead of intervening myself manually.
Could you please suggest me a way on how to do that?
Many thanks for your time!
After diving into your answer, still I don´t understand.
My queries update / insert all of the necessary tables. They practically follow all of the steps from your referred php scripts.
When I check a product in the CMS, I see all of the data - and especially the attributes - correctly loaded. When I press Update manually in the CMS and compare the data in the mySQL tables before and after update, I don't see significant differences. The only thing I see is the value for _product_attributes in wp_postmeta which is slightly different (serialized string).
However, when I experiment with this value (emptying / changing it for the specific post in wp_postmeta), nothing changes in the attributes - and all still works when filtering.
Which brings me to the questions:
- What exactly happens when pressing 'Update' manually?
- Is there another storage except for the mySQL tables in which parts are somehow connected?
- Would it be possible for me to 1) take the 'create product' procedure you referred to for granted and skip it (as I ran my own queries) and then 2) only call the exact procedure that runs when pressing Update - to let it 'tie' everything together without re-creating all of the database entries?
- If so, where would I find this specific procedure?
Your help is much appreciated. Thanks! Thom