Skip Navigation

[Resolved] Adding a conditional taxonomy to content template

This support ticket is created 4 years, 1 month 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 2 voices.

Last updated by hanaelS 4 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1804689
screenshot.jpg

Tell us what you are trying to do?
An output (here an anchor in link) changes depending if the post has a certain taxonomy.

Example: hidden link

Conditional applies the following way:
- by default, clicking on format in the Choose your format section opens a contact lightbox.
- clicking on a Live Online Classes should open a different lightbox (to enroll)

=> the link behind the tile changes if the post taxonomy has the Live Online Class format attached.
Note that all solutions have more than one format attached.

Is there any documentation that you are following?
This thread is similar to my issue: https://toolset.com/forums/topic/adding-a-conditional-taxonomy-to-content-template/

I've followed the solution, especially the has_term() part.

What is the link to your site?
hidden link

#1805565

Hello and thank you for contacting the Toolset support.

Currently, you are putting the opening <a> tag inside the conditional just to change the link. I would suggest that you put the conditionals inside the "href" attribute:

<a href="#[wpv-conditional if="( has_term('Dallas', 'region', null) eq '0' )" ]lightbox-contact[/wpv-conditional][wpv-conditional if="( has_term('Dallas', 'region', null) eq '1' )" ]lightbox-online-course[/wpv-conditional]"></a>

Please note that you will need to pass the taxonomy slug in the second argument. I am not sure if "format" is your taxonomy slug.

If you are still encountering issues with these conditionals, allow me temporary access to check this further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1810409

I tried to find out exactly where the conditional is being used to no avail. What I found so far is this UX Block that has a condition on the taxonomy Formats, but I am not sure.
hidden link

Can you point me exactly to what condition is not working? Can you share a URL and a screenshot so I am sure we are talking about the same condition?

#1810417
Capture d’écran 2020-10-13 à 16.34.42.png

Sorry for that, Jamal.

You'll find the condition in Toolset > Content templates > Loop - Format item
hidden link

For instance, I've used this conditional in the UX block you've mentioned and it works fine. But not in the content template.

#1811149

It will not work inside the content template, because the content template is bound to a post from the Repeatable field groups formats, as you may see in this attached screenshot hidden link

The Repeatable field group "Formats" is a hidden custom post type and is not assigned to the taxonomy "Formats". It can't be assigned to the taxonomy because it is a hidden post type.

The parent post type "Solutions" is on the other hand assigned to the taxonomy format.

So, we can change the context of the current post inside the view (which is currently the Repeatable field group) to its parent(Solution post type) using a content template. For that reason, I have created the content template "Solution link from RFG Formats", which you can update from the link below. And I have moved the link to it.
hidden link

Then I have used it inside the content template "Solution link from RFG Formats" using the item attribute with the following code:

[wpv-post-body view_template="solution-link-from-rfg-formats" item="@formats.parent"]

Read more about the item attribute on this article https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

I hope this helps. Let me know if you have any questions.

#1812281
Capture d’écran 2020-10-15 à 12.48.29.png

Ok, I get it!

I realize my conditional as I explained and structured it is wrong (although what I learned from you is greatly valuable). Let me rephrase it (and sorry for the inaccuracy):

Format "cards" open a contact lightbox on clic. This works. Yet I need that if the format is Live Online Class, then a specific lightbox opens on clic only for this specific card (the lightbox will contain upcoming online class and Enroll buttons).

Cf attachment.

#1812417

Do you mean check against these values hidden link ?
These are custom fields of the repeatable fields group, instead of a term in a taxonomy.

I thought that you were trying to check against the "Formats" taxonomy that we can see here hidden link

If it is the first case, you will need to revert my changes and correct the condition to be against the field:

<a href="#[wpv-conditional if="( $(wpcf-format-type) eq 'Dallas' )" ]lightbox-contact[/wpv-conditional][wpv-conditional if="( $(wpcf-format-type) ne 'Dallas' )" ]lightbox-online-course[/wpv-conditional]"></a>

Please adapt the shortcode with the real values(Dallas is not a real value on your website)

If this does not help, please let me know if the first case is what we are talking about or not?

#1813515

Adapting the condition in the "Solution link from RFG Formats" content template did not work.

Yet I've applied the condition in the "Loop - Format item" content template "at the root" and it WORKS. Basically:

if [condition ok]
  [col_inner span="4" span__sm="6"]
    <a href="#lightbox-contact"> 
    rest of the html code

if [condition not ok]
     [col_inner span="4" span__sm="6"]
    <a href="#lightbox-live-online-classe">
     rest of the html code

It's a little bit less clean as a bunch code is duplicated just to change link. But it does the job. Have a look in the back office, I'll resign your access in the next days.

THANKS a lot Jamal, you've solved my issue. And my apologizes for my initial mistake (it was about the wpcf-format-type, not the taxonomies)