Skip Navigation

[Resolved] Fetch "custom fields" data from a post type

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by thisaraN 6 years ago.

Assisted by: Waqar.

Author
Posts
#1162391

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

#1162697

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

#1165796

My issue is resolved now. Thank you!