Dear Sir/Madam,
I have a post type "coupon", it is possible to have two related parents, "merchant" and "advertiser", I want to get the parent title name if existed by adding code in View
Issued By: [wpv-post-title id="$merchant"], [wpv-post-title id="$advertiser"]
Refer to the screenshot, only the coupon springb-01 has parent relationship to merchant and advertiser, all other shows its title name if no advertiser parent relationship, I suppose it should not be shown.
Best regards,
Kelvin.
Dear Kelvin,
It is expected result, if there isn't parent "advertiser" post set, then the shortcode [wpv-post-title id="$advertiser"] will display the current child "coupon" post information.
In your case, you can use [wpv-conditional] shortcode to check if there is any parent "advertiser" post setting, then display the parent advertiser" post title, for example:
[wpv-conditional if="( NOT(empty($(__wpcf_belongs_advertiser_id))) )"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
Dear Luo Yang,
I paste below code
[wpv-conditional if="( NOT(empty($merchant)))"]
[wpv-post-title id="$merchant"]
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($advertiser)))"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
but still, show the child post title if no parent advertiser
Please try below codes:
[wpv-conditional if="( NOT(empty($_wpcf_belongs_merchant_id)))"]
[wpv-post-title id="$merchant"]
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($_wpcf_belongs_advertiser_id)))"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
The "_wpcf_belongs_merchant_id" and "_wpcf_belongs_advertiser_id" are hidden custom fields for storing the parent post IDs.
Dear Luo Yang,
I tried to copy and paste your code but the same result.
Best regards,
Kelvin.
Thanks for the details, you are right, please modify the codes as below, and test again:
[wpv-conditional if="([wpv-post-id id='$merchant'] ne [wpv-post-id])"]
[wpv-post-title id="$merchant"]
[/wpv-conditional]
[wpv-conditional if="([wpv-post-id id='$advertiser'] ne [wpv-post-id])"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
Above codes will be able to check if the parent post IDs, if they not equal to current child post ID, then display the parent post information.
Dear Luo Yang,
I find my code result is same as yours.
Yours
[wpv-conditional if="( NOT(empty($_wpcf_belongs_merchant_id)))"]
[wpv-post-title id="$merchant"]
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($_wpcf_belongs_advertiser_id)))"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
Mine
[wpv-conditional if="( NOT(empty($merchant)))"]
[wpv-post-title id="$merchant"]
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($advertiser)))"]
[wpv-post-title id="$advertiser"]
[/wpv-conditional]
I have tested above codes in my localhost, it works fine:
https://toolset.com/forums/topic/content-should-be-empty-if-no-parent-relationship/#post-577529
If you still need assistance for it, please provide a test site with same problem, I can setup a demo for you.