Skip Navigation

[Resolved] Display parent metadata in child post

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to setup PHP codes to get related posts.

Solution:

You can use the new relationship API function toolset_get_related_post() to get the related parent post:

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 3 years, 10 months 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by LandruF8417 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1893461

I have the following PHP code to display the address of a parent post 'location' on a page of a child post.

code on child post:

global $wp_query;
$postid = $wp_query->post->ID;
$parent = wpcf_pr_post_get_belongs(get_the_ID(), 'locations');

echo get_post_meta($parent, 'wpcf-address-1', true);

In Views version 3.2.2, the code works fine. But in the recent version 3.3.4 or 3.3.5 of Views, the code dose not work and does not display the data.

What changes do I need to make to my code to make it work in version 3.3.5 of Views?

I am currently using version 3.4.5 of Types.

Thank You

#1893655

Hello,

I assume you have already migrate the Toolset relationships to new post type relationship.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

If it is, you can use the new relationship API function toolset_get_related_post() to get the related parent post:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#1894519

Thanks Luo. I was able to fix it using this code:

$parent_location = toolset_get_related_post( $postid, array( 'locations', 'attorney' ) );

echo get_post_meta($parent_location, 'wpcf-address-1', true);