Skip Navigation

[Resolved] Test if post has parent post of specific custom post type

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

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#556680

Hello,
I am trying to make a cred save data.
It works great but I now need to test - within the function - if the current post has a specific parent post set, or if it's empty.
here is the code I have, but won't work

		if (isset($_POST['_wpcf_belongs_projet_id'])){
	        $title= 'Demande de ' .get_the_title($produit). ' pour ' . get_the_title($projet);
			$name= get_the_title($produit). ' pour ' . get_the_title($projet);
		} else {
	        $title= 'Demande de ' .get_the_title($produit);
			$name= get_the_title($produit);
		}

Result always is first option, even if "projet" parent post type is not set.
Thank you.

#556700

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Roman,

To get the post type of a specific post using the ID you will need to use the following function.
https://developer.wordpress.org/reference/functions/get_post_type/

Then you will need to check against some static value in an if statement to see if it is the post type you are looking for .

Is this the only code that you have so far for this ? Also under what context will this code be used.

Please let me know.

Thanks,
Shane

#559153

Thank you.
Please don't close this thread yet.

#559263

Solved thanks to

if (isset($_POST['_wpcf_belongs_projet_id']) && !empty($_POST['_wpcf_belongs_projet_id']) ){