Skip Navigation

[Resolved] Conditional logic no longer working

This thread is resolved. Here is a description of the problem and solution.

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 3 years, 7 months 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
- 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)

This topic contains 2 replies, has 2 voices.

Last updated by guyA-2 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1768993

Hi there, on this page (hidden 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

Languages: English (English )

Timezone: 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:
=> hidden 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!

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