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!
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.
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;
}
}
}
}
}
}
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
Hello Caridad,
You will find my access details attached to this reply. Hopefully you can see where it goes wrong.
-Kevin
Dear Kevin
I passed this information to the developers, I will get back to you when I have something.
Regards
Caridad
Dear Caridad,
sorry, i cannot provide any credentials for now.
hope you can fix this issue in the next update.
regards,