Skip Navigation

[Resolved] condition doesn't work if several types is used

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
- 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+01:00)

This topic contains 10 replies, has 2 voices.

Last updated by antonK-2 9 months, 2 weeks ago.

Assisted by: Nigel.

Author
Posts
#2640637
Снимок экрана 2023-09-04 в 15.11.18.png

I am trying to: use one template with different parent/child post types. Child condition looks at parent field value. In child condition is used 2 different parent types with OR:

( empty( $(glavanastavnika).item(@miupeduch.parent)) OR empty( $(wpcf-glavanastavnika).item(@miuandmironline.parent)) )

I expected to see: content will be displayed depends from post type is used

Instead, I got: nothing is displayed. If remove one condition then content is displayed.

#2640903

Nigel
Supporter

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

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

Hi Anton

I'm trying to understand the context and exactly what you are trying to do, can we please clarify that.

I believe you have two parent:child relationships.

What post types are involved in the two relationships?

From your question I'm guessing that both relationships have the same child post type but different parent post types. Both parent post types have the same custom field.

You are using a content template for the child post type, and adding the conditional tests to that template, checking the values of the custom field of either parent.

Is that correct, or something else?

#2640945

Parent 1 and Child 1
Parent 2 and Child 2

There are 4 different post types.

I’m using one template for both child posts types.

Content is depends from parent field value.

condition contains both parent:

( empty( $(glavanastavnika).item(@parent1)) OR empty( $(wpcf-glavanastavnika).item(@parent2)) )

But if I’m using both parent types in condition then content is not displayed, while if using only one it’s displayed.

I can grant access if it will help .

#2641061

Nigel
Supporter

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

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

Thanks for clarifying.

I don't need access, I've set up something very similar on my own site, and I'm having trouble getting any combination or variation to work.

I'm out of time for today, so I'll resume looking into it in the morning.

One question, though, is whether it is feasible to use different combinations of conditions to achieve what you want.

You could, for example, have a condition to test if we are currently viewing a post of type Child 1, and then nest a condition to test the field value from Parent 1. Then another condition to test if we are currently viewing a post of type Child 2, and then nest a condition to test the field value from Parent 2.

Would something like that work? Combining conditions testing related content is proving very tricky.

#2641647

I tested single child 1 and then single child 2 conditions. In each case it works.

As soon as I put both conditions there are display nothing in both child posts.

#2641779

Nigel
Supporter

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

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

What exactly were the conditions you tested? The same as before, or did you try splitting out the conditions and nesting them as I suggested in my previous reply?

Combining conditions with AND or OR is not the same as nesting separate conditions.

(Combing conditions which test data of related posts isn't working properly, and I will escalate that to the developers, but I'm trying to see whether there is a solution that can work for you now.)

#2641815

like below, right?

( ( ( '[wpv-post-type ]' eq 'miryiudely' ) AND empty( $(wpcf-glavanastavnika).item(@miuandmironline.parent)) ) OR ( ( '[wpv-post-type ]' eq 'miuch' ) AND empty( $(wpcf-glavanastavnika).item(@miupeduch.parent)) ) )

Separately it works:
( '[wpv-post-type ]' eq 'miryiudely' ) AND empty( $(wpcf-glavanastavnika).item(@miuandmironline.parent)) )

BUT both parent types doesn't work.

#2641817

additionally tested below but it also doesn't work with both parent types:

( ( ( '[wpv-post-type ]' eq 'miryiudely' ) AND ( empty( $(wpcf-glavanastavnika).item(@miuandmironline.parent)) AND ( '[wpv-post-type ]' eq 'miryiudely' ) ) ) OR ( ( '[wpv-post-type ]' eq 'miuch' ) AND ( empty( $(wpcf-glavanastavnika).item(@miupeduch.parent)) AND ( '[wpv-post-type ]' eq 'miuch' ) ) ) )

#2641819

please advise if nested should be used in different way. Thank you in advance!

#2641859

Nigel
Supporter

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

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

Screenshot 2023-09-07 at 17.34.02.png

No, I meant nesting conditional blocks (each with one condition), so you have a structure like in my screenshot.

So the outer block would test if the current post type is child-1 and then the inner condition—knowing that the current post is of type child-1—would test a condition relating to a parent of child-1.

You would have similar nested conditions where the outer block was checking if the current post type is child-2, etc.

I don't know if that logic works for you, but if so it will allow you to move forward with a single template assigned to both child post types (rather than having to create separate templates for each post type).

#2641907

got it, unfortunately such approach means that I have to anyway double content for each block. While I would like to avoid it. Is there only way, right? no other solution?

#2641913

I've found that I can put one template inside 2 conditional blocks. Construction will be more complicated but content will not be doubled. Thank you for this workaround!

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