Skip Navigation

[Resolved] Parent post information does not render PHP

This support ticket is created 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by davidZ-4 7 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#580472

I am trying to: get and display parent post using php

Link to a page where the issue can be seen: hidden link

I expected to see: the line populated with values i.e. assumed infleation 2 returen 5 : tax 40

Instead, I got: line only with no values "asumed infleation returen: taxauthor"
the code i'm using for the test is

// get user assumptions from parent
		$parent_assump_post_id = wpcf_pr_post_get_belongs(get_the_ID(), 'assumption');
		$inflin_frm_assump = get_post_meta($parent_assump_post_id, 'wpcf-bas-anul-infl-rat', true);
		$rtrn_frm_assump = get_post_meta($parent_assump_post_id, 'wpcf-avrg-exp-anul-rtrn', true);
		$rtrn_tax_assump = get_post_meta($parent_assump_post_id, 'wpcf-avrg-tax-rate', true);

		echo '<p>asumed infleation ' . $inflin_frm_assump . ' returen: ' . $rtrn_frm_assump . 'tax' . $rtrn_tax_assump . 'author' . $parent_assump_post_id .'</p>';

please advise,
thanks,

David

#580573

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

It looks like you are trying to use this code on a WordPress page, rather than a post.

I would expect you to have created parent-child relationships with Types between two different post types (e.g. projects -> tasks ), and then add code on the template for the single child posts use code to retrieve the id of the parent post to be used as you will.

But the link you shared appears to be a static WordPress page and so I guess it is not a Types child of another post and hence there is no parent id to retrieve.

If you want to clarify how post relationships work in Toolset I suggest you have a quick read through https://toolset.com/documentation/beyond-the-basics/post-relationship-concepts/

In any case, I suggest you turn on debugging.

Edit your wp-config.php file and change the line with WP_DEBUG like so:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will create a debug.log file in your wp-content directory which you can examine in any text editor.

Now add a line in your code to print the parent id you have retrieved to the log to confirm that the expected parent id has been returned by the function:

error_log("parent id is " . $parent_assump_post_id);
#580943

hi Nigel,
my issue was solved.

thanks,

David