Skip Navigation

[Gelöst] Conditional logic no longer working

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 4 Jahren, 2 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von guyA-2 vor 4 Jahren, 2 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1768993

Hi there, on this page (versteckter Link) 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

Sprachen: Englisch (English )

Zeitzone: 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:
=> versteckter Link

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!