You should be using the pods_api_post_save_pod_item_{podname}
filter instead.
Here’s the documentation link: https://pods.io/docs/code/action-reference/pods_api_post_save_pod_item_podname/
-
This reply was modified 6 years, 5 months ago by
Jim True.
Thanks for the fast support. So I should have 2 functions? First pods_api_post_save_pod_item_{podname}
and then the one I used in the original post?
nope, you would use pods_api_post_save_pod_item_auto
in place of wp_insert_post_data
in your add_filter above.
I have tried it but cannot get it to work. How to get the values from the page to pass in the function? Like model, brand, etc. In my case i have a relation with a custom taxonomy “brands” which has an id to the brand as value. How to get the brand name passed in the title?
You would need to locate those fields within the $pieces array like the examples found on both of those pages. If you’re not comfortable with the PHP, you are welcome to drop onto our Slack Chat at https://pods.io/chat/ and see if you can hire a developer to help you with it, but it’s pretty much required for you to have a good handle on PHP if you’re going to be working with action hooks and filters. Without knowing your exact structure, all your fields, how they connect and how they’re named, there’s no way we can provide you the answer easily.
If you’re working with relationship values and those are the ones you want to replace the post_title, you’re going to have to open up connections to the other post types and grab those values as part of your post-save filter. Those values aren’t ‘in the page’ they’re displayed in the form, but they aren’t part of the $pieces array, because the only connection is the post ID of the post on the other side of the relationship. You could fairly easily grab that post id for ‘brands’ from your $pieces value and
$brands = pods('brand',$brand-id);
$brand-name = $brands->display('post_title');
I’m not a PHP Developer, but that’s pretty much what you’re doing if you’re trying to pull values from your other relationship fields and write them into the post-title of this post you’re saving: you’re opening those pods objects and looking up the record by it’s id and pulling it’s ‘name’ out of the post_title.