Update a pod field on save
-
Hello all
im having a little problem… this is my scenario
– I have a custom pod type called ‘Course’ with a bunch of custom fields
– Everytime i save (or publish) a new Course i automatically create a new Woo product based on data i have on the Course post
– Once the product is created i send back to the post the newly created product and i would like to store in a read only field (so i can later link the product from the Course post)It almost works everything correctly, but im not able to update/save the url field at the end of the procedure… my code looks as follow:
add_action('save_post_course','save_post_callback'); function save_post_callback($post_id){ //CODE THAT SAVE THE PRODUCT (THE PRODUCT IS CORRECTLY CREATED) //THEN I GRAB THE PERMALINK OF THE JUST CREATED PRODUCT (AND IT WORKS IF I LOG IT) $permalink=$permalink=get_permalink( $product_id ); //THEN I TRY TO SAVE THE PERMALINK IN A POD FIELD BUT IT DOESNT SAVE AND GAVE NO ERROR $mypod = pods( 'course', $post_id ); $mypod->save( 'product_url', $permalink); }
i tried thousand of variation (passing the data as array, passing th post_id again, passing a fixed string to test, saving in other fields), but no matter how, the permalink is not stored; im pretty sure $mypod is correct, since if i log a display of a field of it it reports the correct value.
i created hundreds of products with test (in production i would like to check if the product_url is already full to skip the product creation).
im getting lost and im moving torward making a raw sql query… but i would try to stick to pods functionality API if someone can give me a clue!
[EDIT]
it looks like (but im not sure) that when i save a custom post, and i hook in it with
save_post_course
the value of the field coming from the page (the submit data) is always having precedence over the$pod->save
code part. I noticed if i add a die at the end of the function the save is working, if i remove the ‘die’ and have the page reload (as i want!) the value is overwritten byt the on coming from the post. So im stuck, how can i save the product permalink in the post in a single shot?
- The topic ‘Update a pod field on save’ is closed to new replies.