Skip Navigation

[Résolu] Conditional logic no longer working

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

Problem:
How to display conditional content based on post type archive title.

Solution:
You can use the [wpv-conditional] shortcode with custom shortcode that returns the archive title.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/conditional-logic-no-longer-working/#post-1769219

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

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

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par guyA-2 Il y a 4 années et 2 mois.

Assisté par: Minesh.

Auteur
Publications
#1768993

Hi there, on this page (lien caché) we have some conditional logic set up to display which therapies each therapist offers, within therapists-archive. The code is as follows:

[wpv-conditional if="( '[wpv-archive-title]' = 'Archives: Therapists' )"]
<p class="btn small">[types field='first-name'][/types] offers</p>
[wpv-view name="therapies-list-view"][/wpv-conditional]
[wpv-conditional if="( '[wpv-archive-title]' = 'Archives: Teachers' )"]
<p class="btn small">[types field='first-name'][/types] teaches</p>
[wpv-view name="classes-list-view"][/wpv-conditional]

This was working fine but has now stopped. We've tested wpv-archive-title and it matches both 'Archives: Therapists' and 'Archives: Teachers'. We can't figure out why this has stopped working.

Can you look into this please? Thanks.

#1769219

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset use the WordPress function get_the_archive_title() to get the current archive title. The function get_the_archive_title() return the archive title name with span tag. For example: Archives: <span>Therapists</span>

That is the reason the conditional statement was broken.

To make conditional works, we will require to remove the span tag from the archive title returned from WordPress.

I've added the following shortcode to the "Custom Code" section offered by Toolset:
=> lien caché

function func_get_current_archive_title( $atts ) {
 
return trim(strip_tags(get_the_archive_title()));
 
}
 
add_shortcode( 'get-current-archive-title', 'func_get_current_archive_title' );

And I've used the above shortcode with the conditional statement as given under:

[wpv-conditional if="( '[get-current-archive-title]' eq 'Archives: Therapists' )"]
        <p class="btn small">[types field='first-name'][/types] offers</p>
     	 [wpv-view name="therapies-list-view"]
      [/wpv-conditional]
      
      [wpv-conditional if="( '[get-current-archive-title]' eq 'Archives: Teachers' )"]
      <p class="btn small">[types field='first-name'][/types] teaches</p>
        [wpv-view name="classes-list-view"]
      [/wpv-conditional]
   

More info:
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1769295

Ok, I don't understand how it was working before and then stopped working when we didn't change anything. But my issue is resolved now, so thank you!