Skip Navigation

[Gelöst] Conditional Display Using Checkbox Value and PHP

This support ticket is created vor 2 Jahre, 10 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 1 Antwort, has 1 Stimme.

Last updated by julieP vor 2 Jahre, 10 Monate.

Author
Artikel
#2065421

I have a Checkboxes field with options 1 and 2 and set to save nothing if unchecked. I can display the checked values using types_render_field() but my code to display content based on the value(s) saved for the field isn't generating the correct output. This is my code:-

$option1 = 'A';
                    $option2 = 'B';  
                    $values = types_render_field( "apply-to-list", array("post_id" => '20', "separator" => ", " ) );                     
                    $values_arr = explode(', ', $values);
                     
                    if (in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
                        echo '<p>A and B</p>';
                    } else if (in_array($option1, $values_arr) && !in_array($option2, $values_arr)) {
                        echo '<p>A</p>';
                    } else if (!in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
                        echo '<p>B</p>';
                    } else {
                        echo '<p>Neither A nor B</p>';
                    }

The uploaded image shows the value in the database is A but the output on the page is "Neither A nor B".

Any ideas please?

#2065425

I discovered the values to check against are the checkbox title not the value saved to the database

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