Skip Navigation

[Closed] Wrong custom checkbox values after update

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 6 replies, has 3 voices.

Last updated by danielK-8 9 years, 7 months ago.

Assisted by: Caridad.

Author
Posts
#244244

Hello,

I'm sorry, I accidentally closed the topic where I issued my problem below:

After updating the Types plugin, it seems that something has changed in the way checkboxes are stored.

I've found the right way to display the values on the frontend for new posts. But the posts that already exist, display their values in a strange way. Sometimes just the first letter of a value. Or a '0' instead of an empty field.

This problem is solved by re-saving a post (i.e. opening it and then saving it). I've tried re-saving multiple posts via bulk edit, but this doesn't seem to have an affect on the custom checkbox fields.

Is there a way to fix this without opening and re-saving the 2000 posts on the website by hand?

I hope you can be of help. I have an account made for you, so you can login on the test site. How can I send this in private?
Thanks in advance!

#244256

Hi, we've got the same problem here but no solution yet. After updating, there's an issue with checkbox fields that use the "save 0 to the db"-setting.
instead empty meta values are stored which now confuses the logic we use to display and manipulate all metadata.

on digging depper into the guts of types,
i found that as soon as there's an postmeta entry in the db (even with empty value) the migration function (switching between field's db settings) no longer works correctly as it expects either a zero-valued post meta or none at all.

so afaik some modifications need to be made either on initial post meta creation to the least (some functions attached to the 'save_post' hook) OR extra checks need to be made (in file: includes/fields.php) on the data migration functions to take this scenario into account.

#244265

found something:
in includes/embedded/fields/checkbox.php line 236

 if ( isset( $_POST['_wpcf_check_checkbox'] ) ) {

this post variable is no longer existing, it was a hidden field to yield an array, attached to each checkbox and contained as its keys a specific child id aka post id.
now that logic has somewhat changed.
here is what i did and it seems to do the trick:

replace

    if ( isset( $_POST['_wpcf_check_checkbox'] ) ) {

        // Loop and search in $_POST
        foreach ( $_POST['_wpcf_check_checkbox'] as $child_id => $slugs ) {
            foreach ( $slugs as $slug => $true ) {

                $cf->set( $child_id, $cf->__get_slug_no_prefix( $slug ) );

                // First check main post
                if ( $mode == 'save_main'
                        && intval( $child_id ) == wpcf_get_post_id() ) {
                    if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                        $meta_to_unset[intval( $child_id )][$cf->slug] = true;
                    }
                    continue;
                }

                // If new post
                if ( $mode == 'save_main' && $child_id == 0 ) {
                    if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                        $meta_to_unset[$post_id][$cf->slug] = true;
                    }
                    continue;
                }
                /**
                 * Relationship check
                 */
                if ( $mode == 'save_main' ) {
                    if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                        $meta_to_unset[$post_id][$cf->slug] = true;
                    }
                    continue;
                } else if ( !empty( $_POST['wpcf_post_relationship'] ) ) {
                    foreach ( $_POST['wpcf_post_relationship'] as $_parent => $_children ) {
                        foreach ( $_children as $_child_id => $_slugs ) {
                            if ( !isset( $_slugs[$slug] ) ) {
                                $meta_to_unset[$_child_id][$cf->slug] = true;
                            }
                        }
                    }
                }
            }
        }
    }

with

    if ( isset( $_POST['_wptoolset_checkbox'] ) && isset($_POST['post_ID']) ) {
        $child_id = $_POST['post_ID'];
        // Loop and search in $_POST
        foreach ( $_POST['_wptoolset_checkbox'] as $slug => $value ) {

            $cf->set( $child_id, $cf->__get_slug_no_prefix( $slug ) );

            // First check main post
            if ( $mode == 'save_main'
                    && intval( $child_id ) == wpcf_get_post_id() ) {
                if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                    $meta_to_unset[intval( $child_id )][$cf->slug] = true;
                }
                continue;
            }

            // If new post
            if ( $mode == 'save_main' && $child_id == 0 ) {
                if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                    $meta_to_unset[$post_id][$cf->slug] = true;
                }
                continue;
            }
            /**
             * Relationship check
             */
            if ( $mode == 'save_main' ) {
                if ( !isset( $_POST['wpcf'][$cf->cf['slug']] ) ) {
                    $meta_to_unset[$post_id][$cf->slug] = true;
                }
                continue;
            } else if ( !empty( $_POST['wpcf_post_relationship'] ) ) {
                foreach ( $_POST['wpcf_post_relationship'] as $_parent => $_children ) {
                    foreach ( $_children as $_child_id => $_slugs ) {
                        if ( !isset( $_slugs[$slug] ) ) {
                            $meta_to_unset[$_child_id][$cf->slug] = true;
                        }
                    }
                }
            }
        }
    }
#244358

Dear Daniel

Let me get a developer to look into this, meanwhile can you provide access details in case we need them?

You can use the boxes below the comment area, after you agree to the disclaimer.

Thanks
Caridad

#244380

Hello Caridad,

You will find my access details attached to this reply. Hopefully you can see where it goes wrong.

-Kevin

#244541

Dear Kevin

I passed this information to the developers, I will get back to you when I have something.

Regards
Caridad

#244961

Dear Caridad,

sorry, i cannot provide any credentials for now.

hope you can fix this issue in the next update.

regards,

The topic ‘[Closed] Wrong custom checkbox values after update’ is closed to new replies.