Skip Navigation

[Resolved] How to get value of a field from a custom post with parent post reference field

This support ticket is created 3 years, 1 month 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 4 replies, has 2 voices.

Last updated by fred-r.M 3 years, 1 month ago.

Assisted by: Waqar.


Tell us what you are trying to do? We are having products (WooCommerce) and custom posts Tour Dates. In the tour dates we are having fields I need to get the values.

Both post types are "linked" with a post reference field (where the parent post is referenced).

How do I get values (as php code) from the tour dates custom post type?

Is there any documentation that you are following? I found this,, but not sure if this is the correct "document".

Is there a similar example that we can see?

What is the link to your site?


Dear Waqar

Okay. Do You think this will work?

funtion get_my_tour_date_id () {

	global $post;
    $parent_post = $post->ID;
    $field_slug = 'tour-date-field';
	$results = toolset_get_related_posts( 
		// get posts related to this one
		// Relationship between the posts
		// Additional arguments
			// This is mandatory because we're passing just a single post as the first parameter.
			'query_by_role' => 'child', 
			// pagination
			'limit' => 9999, 
			'offset' => 0,
			'args' => '',
			'role_to_return' => 'other',
			'return' => 'post_id'
	return $results;

If I like to get all date values out - are I am able to use this function, where I used to get the id from the tour_dates?


Thanks for writing back.

To confirm whether this code will work or not, I'll need to see how these post types and fields are set up on your website.

Can you please share temporary admin login details? This will allow me to test the code with a similar setup on my test website.

Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.


Thank you for sharing these details.

Here is a quick example of a shortcode that gets all the related (through post reference field) "Tour Dates" posts of the current "Product" post and then prints their 3 custom field values:

add_shortcode('get_related_TD_fields', 'get_related_TD_fields_func');
function get_related_TD_fields_func() {

	global $post;
	$parent_post = $post->ID;
	$field_slug = 'tourid';
	$get_results = toolset_get_related_posts( $parent_post, $field_slug, 'parent', 1000, 0, array(), 'post_id','child');

	foreach ( $get_results as $result ) {
		$tour_date_field = types_render_field( 'tour-date-field', array( 'item' => $result) );
		echo "tour_date_field: ".$tour_date_field."<br>";
		$tour_price = types_render_field( 'tour-price', array( 'item' => $result) );
		echo "tour_price: ".$tour_price."<br>";
		$supplement = types_render_field( 'supplement', array( 'item' => $result) );
		echo "supplement: ".$supplement."<hr>";
	return ob_get_clean();


You can adjust the output of this shortcode as needed and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:


My issue is resolved now. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.