Skip Navigation

[Résolu] Conditional output using parent id

This support ticket is created Il y a 4 années et 7 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
- 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)

Marqué : 

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

Last updated by Shane Il y a 4 années et 6 mois.

Assisted by: Shane.

Auteur
Publications
#1352695

Tell us what you are trying to do?
I build a restaurant menu using repeater field and cpt.
Each menu section is a different post with and ID and slug.
I try to output if my field (nombre-de-morceaux) is empty and came from the post ID 205/slug sushi-sashimi that is a parent of this repeater field.

What is the link to your site?
hidden link

Thank you

#1353149

Shane
Supporter

Languages: Anglais (English )

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

Hi Louis,

Thank you for getting in touch.

Is it that you want to display a field from the parent if the field on the child is empty?

Not sure I understand fully. Could you provide some more clarity for me.

Thanks,
Shane

#1353187

Hi Shane,
I want to display a text if a certain field (nombre-de-morceaux) is empty AND the parent Id is 205.

The case :
I have a CPT called Sushi menu.
Each meal section is a post of sushi menu.
In every meal/post, there is the sushi items coming as a repeater field.

So in this view
if the field "nombre-de-morceaux" from the repeater field "items-au-menu-sushi" is empty
AND
the repeater field is display from post id 205
THEN
display my text

View name="menu-sushi-items"

<div class="flex-table row" role="rowgroup">
<div class="flex-row first size-2" role="cell"><h4>[types field='nom-du-plat'][/types]</h4></div>
<div class="flex-row size-4" role="cell">[types field="description-du-plat"][/types]</div>
<div class="flex-row size-2" role="cell">[types field='forme-disponible' separator=', '][/types]</div>
<div class="flex-row" role="cell">
[wpv-conditional if="( $(nombre-de-morceaux) ne '' )"]
[types field='nombre-de-morceaux' output='raw'][/types] mcx
[/wpv-conditional]

/*HERE*/
[wpv-conditional if="( $(nombre-de-morceaux) eq '' ) AND ( [wpv-post-slug item="$205"])"]
<div style="font-size:0.83em;">Sushi : 2mcx <br> Sashimi : 3mcx
[/wpv-conditional]

</div>
<div class="flex-row" role="cell">[wpv-conditional if="( $(wpcf-prix-general) ne '' )"][types field="prix-general"][/types] $[/wpv-conditional]</div>

</div>

THANK YOU

#1353219

Shane
Supporter

Languages: Anglais (English )

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

Hi Louis,

Assuming that you are already displaying the items from the repeater fields. The parent you want to check the ID for is the post that the repeatable field is attached to correct?

If so then Its not possible to get the ID of the post that the repeatable fields are attached to.

Which version of views are you currently using ?

Please let me know.
Thanks,
Shane

#1354101

Good morning Shane,
oh, that's bad. Can I check by some other way the post that contain the repeater field?
Any workeround ? If not id, I suppose the slug will not do neither...

And for the version:
Types : 3.3.5
Views : 2.9.2

Thank you again.

#1354119

Shane
Supporter

Languages: Anglais (English )

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

HI Louis,

I know in our latest views Beta you are able get the ID of the parent post type. However since this is a Beta i'm not certain if the code will work in a conditional field.

If you had done this as a post relationship then we would've been able to get the parent ID in the current version of views without any issues at all.

Thanks,
Shane

#1354143

I guess i'll try the beta...
Then what will be the correct code? If you please.

#1354171

Shane
Supporter

Languages: Anglais (English )

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

Screenshot 2019-10-02 at 10.53.09 AM.png

Hi Louis,

When using the dynamic blocks that it provides, you should be able to select the parent ID for the RFG when adding it to the page.

You will need to use the SIngle field dynamic block. See Screenshot

Then it should generate a shortcode like.
[tb-dynamic provider="toolset_relationship|drivers-rfg|parent" post="current" source="post-id" ]

Thanks,
Shane

#1354181

Shane
Supporter

Languages: Anglais (English )

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

I also suggest you have a look at the link below.
https://toolset.com/2019/09/views-3-b1-annoucement/

This will give you a quick overview on how to use this beta plugin.

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