Skip Navigation

[Résolu] Views showing current type variable instead of parent type variable

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Display post link if it has parent.

Solution:
Using [wpv-conditional] shortcode we can check if post has a parent.

When using Types posts relationships, the parent of a given type is stored in a field:

_wpcf_belongs_{parent-slug}_id

Let’s assume that we are displaying a Car post type that has a Maker as a parent post type. Each Car will store its Maker id in the field _wpcf_belongs_maker_id, and you can check if a Car has a Maker using this code:

For example:

[wpv-conditional if="((empty($(_wpcf_belongs_maker_id))))"]
This car has no maker
[/wpv-conditional]

Where:
_wpcf_belongs_{parent-slug}_id = replace your post slug with "{parent-slug}".

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
[Section: "Checking If A Parent Exists"]

This support ticket is created Il y a 8 années et 3 mois. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Marqué : 

This topic contains 2 réponses, has 2 voix.

Last updated by Shreyas Khatri Il y a 8 années et 3 mois.

Assisted by: Minesh.

Auteur
Publications
#359654

I am trying to:
Show parent type's variable (title)

I've two post types:

1) Chefs --> Parent
2) Receipes --> Child

On the recipe detail page, I'm using the following code to show the chef related to the recipe:

<p>By: [wpv-post-link id="$chef"]</p>
[types field="chef-image" width="100" height="100" align="left" resize="proportional" class="img-responsive" id="$chef"][/types]

I visited these URL:

It works as expected when a parent is associated as in:
hidden link and
hidden link

However, when no parent is associated with the recipe, instead of showing the title link empty, it falls back and shows current post type info.

Example: hidden link

Please kindly let me know correct way to code this such that when parent is not defined, nothing shows up.

I expected to see:

Instead, I got:

#359694

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You should wrap your code using [wpv-conditional] shortcode and check if post has a parent.

When using Types posts relationships, the parent of a given type is stored in a field:
_wpcf_belongs_{parent-slug}_id

Let’s assume that we are displaying a Car post type that has a Maker as a parent post type. Each Car will store its Maker id in the field _wpcf_belongs_maker_id, and you can check if a Car has a Maker using this code:

For example:

[wpv-conditional if="((empty($(_wpcf_belongs_maker_id))))"]
This car has no maker
[/wpv-conditional]

Where:
_wpcf_belongs_{parent-slug}_id = replace your post slug with "{parent-slug}".

More information:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
[Section: "Checking If A Parent Exists"]

#359867

Dear Minesh,

Thanks for your support. We could achieve the desired result by applying the mentioned code.

Here's the link:
hidden link

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