Title: Conditional logic bug with date picker
Last modified: June 26, 2020

---

# Conditional logic bug with date picker

 *  Resolved [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/)
 * I’ve seen you’ve added the datepicker to use in the conditional logic options
   within a group (thanks) but I believe its not working correctly.
 * When you set 1 date condition AND an other various condition things work.
 * But when you add an OR statement with again a date condition nothing works anymore.
 * So: DATE = X AND OTHER FIELD = Y >>> Works
 * But: DATE = X AND OTHER FIELD = Y OR DATE = A AND OTHER FIELD = B >>> Nothing
   works anymore.
 * The strange thing though is that the output of the data-condition=”” does come
   up nicely but has no effect at all.
 * Hope you can reproduce this….

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043181)
 * Hello,
 * Thanks for the feedback. I just tested, and the conditions works correctly. I
   advise you to make your tests in the Field Group UI first, before adding your
   conditions in PHP.
 * Here is my setup:
 * – Field1 (Text)
    – Date1 (Date) – Field2 (Text) – Date2 (Date) – Final field (
   Textarea)
 * The conditions on “Final field” are the following:
    `(Field1 == 1 && Date1 ==
   20200627) OR (Field2 == 2 && Date2 == 20200628)`
 * Here is the video example: [https://i.imgur.com/14EPuyX.mp4](https://i.imgur.com/14EPuyX.mp4)
   
   Here is a screenshot of the field UI: [https://i.imgur.com/Hd34mhx.png](https://i.imgur.com/Hd34mhx.png)
 * To help you testing your conditions, you can click on the “Data” button of your
   field in the UI, to display the actual PHP field data (you need to save the field
   group first).
 * See the screenshots: [https://i.imgur.com/Hd34mhx.png](https://i.imgur.com/Hd34mhx.png)&
   [https://i.imgur.com/rZBzT0y.png](https://i.imgur.com/rZBzT0y.png)
 * You most likely have problems in your PHP conditions. Write it manually in PHP
   first, with actual static data, just like I did in: `(Field1 == 1 && Date1 ==
   20200627) OR (Field2 == 2 && Date1 == 20200628)`).
 * Then when it works, make it programmatic.
 * Note: The Datepicker conditional logic are not released yet, it will be published
   in the next patch.
 * Regards.
 *  Thread Starter [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043276)
 * Surely I first insert the conditions via the conditional logic option of the 
   field itself but I got the same negative result.
 * Your setup is slightly different than mine….
 * Try the same thing you did only than: the exact same field + value of the second
   field and only another date in the 1st and 2nd condition combi.
 * F.i.:
 * – Field1 (Text)
    – Date1 (Date) – Field2 (Text) – Date2 (Date) – Final field (
   Textarea)
 * `(Field1 == 1 && Date1 == 20200627) OR (Field1 == 1 && Date1 == 20200628)`
 * That’s where it doesn’t work anymore…
    -  This reply was modified 5 years, 11 months ago by [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/).
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043310)
 * Hello,
 * The condition is working:
 * `(Field1 == 1 && Date1 == 20200627) OR (Field1 == 1 && Date1 == 20200628)`
 * See video: [https://i.imgur.com/e0E7geI.mp4](https://i.imgur.com/e0E7geI.mp4)
   
   Field UI: [https://i.imgur.com/Cj1sMLk.png](https://i.imgur.com/Cj1sMLk.png)
 * You didn’t tested it in the UI like I advised you in my previous answer. Please
   test it in the UI, it will avoid false positives.
 * Regards.
 *  Thread Starter [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043593)
 * I did tested it in the UI, even before I posted the question here, but I found
   out what’s different between your setup and mine.
 * You use:
    date VALUE IS EQUAL TO …..
 * I use:
    date VALUE IS **NOT** EQUAL TO …..
 * Try it and you’ll see it doesn’t work.
 * So exactly the same as you tried the last time but now both DATE VALUES as NOT
   EQUAL TO
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043615)
 * Hello,
 * The condition is working. If you want to deny two dates at once, then it is not
   a bug, it’s because of your condition.
 * In the following rule:
 * `(Field1 == 1 && Date1 != 20200627) OR (Field1 == 1 && Date1 != 20200628)`
 * The field will be displayed regardless if you choose `27/06/2020` or `28/06/2020`,
   because it always fulfill one of the condition, due to the `OR` operator.
 * – Choosing 27/06/2020:
    Display the field because of `Field1 == 1 && Date1 !=
   20200628`
 * – Choosing 28/06/2020:
    Display the field because of `Field1 == 1 && Date1 !=
   20200627`
 * If you want to deny those two dates, you have to merge the `AND` operators:
 * `Field1 == 1 && Date1 != 20200627 && Date1 != 20200628`
 * Field UI screenshot: [https://i.imgur.com/n69HUzx.png](https://i.imgur.com/n69HUzx.png)
 * Regards.
 *  Thread Starter [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043669)
 * Aha… And that’s why you build this plugin and I did nott. Smart thinking 🤔
 * In that case below code does not cut it because it always implements both field
   like this:
 * `DATE != xxx AND Field1 == 1, DATE != yyy AND Field1 == 1, DATE != zzz AND Field1
   == 1`
 *     ```
       // Apply conditions to fields
       add_filter('acf/prepare_field/name=booking_time_session_1', 'yl_check_booking_setting_exceptions_session_1');
       function yl_check_booking_setting_exceptions_session_1($field){
         $conditions = array();
         if (have_rows('booking_setting_exceptions', 'booking_settings')) {
           while (have_rows('booking_setting_exceptions', 'booking_settings')) {
             the_row();
       		if (get_sub_field('booking_setting_exceptions_session') == '1') {
               $date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings')));
               if (empty($date)) {
                 // no date, skip this row
                 continue;
               }
               // Add the condition to the field
               $conditions[] =
                 array(
       			   array(
       				'field'   => 'field_5ed4181bd63dc', // Time field session 1 in the form
       				'operator'  => '==', // If Value is same, then show the field
       				'value'   => '1', // Compare against session option page value
       			  ),
       			 array(
       				'field'   => 'field_5ed4178dd63d7', // Date field in the form
       				'operator'  => '!=', // If Value is different, then show the field
       				'value'   => $date, // Compare against date option page value
       			  )
       			);
       		}
           } // end while have_rows
         } // end if have_rows
         $field['conditional_logic'] = $conditions;
         // Return
         return $field;
       }
       ```
   
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13043707)
 * Hello,
 * In your example, the `,` are `OR` operators. So you do:
 * `(DATE != xxx AND Field1 == 1) OR (DATE != yyy AND Field1 == 1) OR (DATE != zzz
   AND Field1 == 1)`
 * Concerning your PHP code, as I explained in the other topic where you asked question
   about PHP implementation, doing `$conditions[]` at the first level adds an `OR`
   opeartor.
 * You should do something like that:
 *     ```
       add_filter('acf/prepare_field/name=booking_time_session_1', 'yl_check_booking_setting_exceptions_session_1');
       function yl_check_booking_setting_exceptions_session_1($field){
   
           // Reset conditions
           // Warning: Conditions set in the UI won't be compatible!
           $conditions = array();
   
           // Creating Base Condition
           $conditions[] = array(
               array(
                   'field'     => 'field_5ed4181bd63dc',
                   'operator'  => '==',
                   'value'     => '1',
               )
           );
   
           if(have_rows('booking_setting_exceptions', 'booking_settings')):
               while(have_rows('booking_setting_exceptions', 'booking_settings')): the_row();
   
                   // Check: Booking Settings Exceptions Session
                   if(get_sub_field('booking_setting_exceptions_session') != '1')
                       continue;
   
                   $date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings')));
   
                   // Check: Booking Settings Exceptions Date
                   if(empty($date))
                       continue;
   
                   // Adding a new AND condition inside Base condition, at the index = 0
                   $conditions[0][] = array(
                       'field'     => 'field_5ed4178dd63d7',
                       'operator'  => '!=',
                       'value'     => $date,
                   );
   
               endwhile;
           endif;
   
           // Setting the full condition
           $field['conditional_logic'] = $conditions;
   
           /*
            * $conditions looks like:
            * 
            * Array(
            * 
            *    // OR
            *    Array(
            *        
            *        // AND
            *        Array(
            *                [field] => field_5ed4181bd63dc
            *                [operator] => ==
            *                [value] => 1
            *        )
            *
            *        // AND
            *        Array(
            *                [field] => field_5ed4178dd63d7
            *                [operator] => !=
            *                [value] => 20200627
            *        )
            *
            *        // AND
            *        Array(
            *                [field] => field_5ed4178dd63d7
            *                [operator] => !=
            *                [value] => 20200628
            *        )
            *        
            *    )
            *    
            * )
            */
   
            return $field;
   
       }
       ```
   
 *  Thread Starter [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13044470)
 * After weeks I’m finally there with this data-condition code. Many tnx.
 * I have bought you a couple of drinks so you won’t dry out 😉
 * SOLVED
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13044970)
 * Hello,
 * I’m glad to see it’s now working as you want. Thanks for the coffees 🙂 It will
   keep me awake to develop the next features!
 * Have a nice day.
 * Regards.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Conditional logic bug with date picker’ is closed to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-bug-with-date-picker/#post-13044970)
 * Status: resolved