Home › Forums › Bug Reports › Trying to access offset value of type bool › Reply To: Trying to access offset value of type bool
One of ACF’s function is returning false when looking by field name. What you’re going to need to do is check to see if the field has a value before attempting to delete it.
function delete_field( $selector, $post_id = false ) {
// filter post_id
$post_id = acf_get_valid_post_id( $post_id );
// get field
$field = acf_maybe_get_field( $selector, $post_id );
// delete
return acf_delete_value( $post_id, $field );
}
acf_maybe_get_field() is returning false
acf_delete_value() expects $field to be an array, which it is not.
The last line of this function should likely be
if ($field) {
return acf_delete_value( $post_id, $field );
}
of the function acf_delete_value() should be checking to see if $field has a value before attempting to use it.
I would call this a bug. You should submit it here https://www.advancedcustomfields.com/contact/
In the mean time, as a fix, you can either use the field key when calling these or check for a value.
I would use the field key because as I already mentioned update_field() using the field name where the field does not already have a value will fail to save a value. This is covered in the documentation for this function https://www.advancedcustomfields.com/resources/update_field/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp
— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.