Skip Navigation

[Resolved] WPV If Statements broken and conditional logic not firing

This support ticket is created 6 years, 11 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
- 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+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Adrian 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#604946

I am trying to use conditional logic to display markers with different colors based on different conditions.
The conditions are fine, however the shortcodes for the custom fields are not rendered as values, making the comparison null.

The field wpcf-start-date is of type date, and seems to display fine otherwise. I noticed that if I place the field inside an HTML comment such as `<!-- [types field='start-date' output='raw'][/types] -->` it renders on the page as `<!-- [types field='start-date' output='raw'][/types] -->`

Here is the code in question:

[wpv-conditional if="( $(wpcf-start-date) lt '[now]' ) AND $(wpcf-start-date) ne '' )" debug="true"]

This shows the following debug

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(wpcf-start-date) < '1515563880' ) AND $(wpcf-start-date) ne '' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-start-date) < '1515563880' ) AND $(wpcf-start-date) ne '' )
--------------------
After matching 1 numeric strings into real numbers: ( $(wpcf-start-date) < 1515563880 ) AND $(wpcf-start-date) ne '' )
	Matched '1515563880' to 1515563880
--------------------
Converted expression: ( 1528390800 < 1515563880 ) AND 1528390800 ne '' )
--------------------

Here is the full view I created for the custom pos type:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		[wpv-map-render map_id="map-1" map_width="100%" map_height="800"]
		
		<wpv-loop>
          
<!-- [wpv-post-title] marker -->
[wpv-conditional if="( $(wpcf-start-date) lt '[now]' ) AND $(wpcf-start-date) ne '' )" debug="true"] 
<!-- Event is not passed -->
          	            
          [wpv-conditional if="( $(wpcf-buy-ticket-url) ne '' )"]
            [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
                <!-- URL Found, Adding Button -->
          		<h2>[wpv-post-title]</h2>
          		[wpv-conditional if="( $(wpcf-start-date) eq '' ) AND ( $(wpcf-tentative-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='tentative-date'][/types]
         		</span>
          		[/wpv-conditional]
          		[wpv-conditional if="( $(wpcf-start-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='start-date' style='text' format='F j, Y'][/types]
         		</span>
          		[/wpv-conditional]
                <a class="event_link" href="[wpv-post-url]">Register</a>
          	  
            [/wpv-map-marker]
          [/wpv-conditional]
          
          
          [wpv-conditional if="( $(wpcf-buy-ticket-url) eq '' )"]
           <!-- HAS NO TICKETS -->
          	[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
                <!-- No URL Found, Adding Form -->
          		<h2>[wpv-post-title]</h2>
          		[wpv-conditional if="( $(wpcf-start-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='start-date' style='text' format='F j, Y'][/types]
          		</span>
          		[/wpv-conditional]
          		<p>More information coming soon. Sign up below to get notified.</p>
                [gravityform id="1" title="false" description="false" ajax="true" tabindex="9999" field_values="event_name=[wpv-post-slug]"]
            [/wpv-map-marker]
           
          [/wpv-conditional]
          
           
          [wpv-conditional if="( $(wpcf-buy-ticket-url) eq '' ) AND ( $(wpcf-tentative-date) ne '' )"]
           <!-- HAS NO TICKETS BUT A TENTATIVE DATE -->
          	[wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
                <!-- No URL Found, Adding Form -->
          		<h2>[wpv-post-title]</h2>
          		[wpv-conditional if="( $(wpcf-start-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='start-date' style='text' format='F j, Y'][/types]
          		</span>
          		[/wpv-conditional]
          		[wpv-conditional if="( $(wpcf-start-date) eq '' ) AND ( $(wpcf-tentative-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='tentative-date'][/types]
          		</span>
          		[/wpv-conditional]
          		<p>More information coming soon. Sign up below to get notified.</p>
                [gravityform id="1" title="false" description="false" ajax="true" tabindex="9999" field_values="event_name=[wpv-post-slug]"]
            [/wpv-map-marker]
           
          [/wpv-conditional]
          
[/wpv-conditional]
          

[wpv-conditional if="( $(wpcf-start-date) lte '[now]' ) AND ( $(wpcf-start-date) ne '' )"]
<!-- Event is passed -->
          [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
                <!-- URL Found, Adding Button -->
          		<h2>[wpv-post-title]</h2>
          		<p>Event has passed</p>
          		[wpv-conditional if="( $(wpcf-start-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='start-date' style='text' format='F j, Y'][/types]
         		</span>
          		[/wpv-conditional]
                <a class="event_link" href="[wpv-post-url]">View Event</a>
            [/wpv-map-marker]
[/wpv-conditional]  
          

[wpv-conditional if="( $(wpcf-start-date) eq '' )"]
<!-- Event has no start date -->
          
    [wpv-conditional if="( $(wpcf-tentative-date) eq '' )"] 

          [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
               
          		<h2>[wpv-post-title]</h2>
          		
          		[wpv-conditional if="( $(wpcf-tentative-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='tentative-date'][/types]
          		</span>
          		[/wpv-conditional]
                  
                <a class="event_link" href="[wpv-post-url]">View Event</a>
          [/wpv-map-marker]
     [/wpv-conditional]
     [wpv-conditional if="( $(wpcf-tentative-date) ne '' )"]
          [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" marker_icon="<em><u>hidden link</u></em>" marker_title="[wpv-post-title]" marker_field="wpcf-event-address"]
               
          		<h2>[wpv-post-title]</h2>
          		
          		[wpv-conditional if="( $(wpcf-tentative-date) ne '' )"]
          		<span class="pin_start_date">
                  <i class="fa fa-calendar-o" aria-hidden="true"></i> [types field='tentative-date'][/types]
          		</span>
          		[/wpv-conditional]
                  
                <a class="event_link" href="[wpv-post-url]">View Event</a>
          [/wpv-map-marker]
     [/wpv-conditional]   
          
[/wpv-conditional]
        </wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

This just started happening today, can't say I changed anything to affect this.

#605068

Nigel
Supporter

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

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

Hi Adrian

I am right in saying this was working previously and has now stopped working?

There have been problems with complex conditional statements that have arisen with PHP 7. If you have recently switched to PHP 7 that could account for why they have stopped working.

From your question I'm not entirely sure what is and is not working, though.

You include the debug info of one conditional shortcode which appears to show that it is working correctly. The wpcf-start-date custom field is evaluated as 1528390800 and then tested against the value generated by your now shortcode, 1515563880.

The test fails because 1528390800 is greater than 1515563880.

#605070

Hi, thank you for your help. It’s resolved.