Hi there,
I have a car listing website, it has a custom post type named "Vehicles". The vehicle listing has three custom fields (name, email, phone) that I need to use for a different post type named "Invoices".
Basically, all I need is to generate an invoice (create a post in the "Invoices" post type) for a particular vehicle with the name, email & phone fetched from "Vehicles" post type. I'm not sure how to achieve that.
What I thought I could do is, try to use the "post-relationship" option & create a one to one relationship with the Vehicles - Invoices & fetch the name, email, phone from "Vehicles" post type to show on the "Invoices" post.
In the "Invoices" post type, I have a repeating field to add amounts & a PHP code (in the themes functions.php) to calculate the amounts to show as an invoice in the front end.
I'm missing the name, email & phone fields when generating an "invoices" post. I still haven't figured out how to save the created post page as a PDF. But right now all I need is to know how to retrieve data from a post type to show in another.
I hope my issue makes sense.
Cheers
Hi there,
Thank you for contacting us and I'll be happy to assist.
Your understanding is correct and you can use post relationships to link specific vehicle and invoice.
( ref: https://toolset.com/documentation/post-relationships/ )
After your vehicles and invoices are linked together through post-relationship, you'll be able to get the value of the linked post in the PHP code, using the "toolset_get_related_posts" function from the "Post Relationships API":
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Once you've got the ID of the connected vehicle post, you'll be able to use the "Types Fields API", to get the values of the required custom fields from it:
https://toolset.com/documentation/customizing-sites-using-php/functions/
I hope this helps.
regards,
Waqar
My issue is resolved now. Thank you!