I'm hoping this is the best place to post this. I'm using both Relationships and Frontend Submissions but I think the possible bug is in the main Metabox plugin.
I have a relationship between 2 CPTs and I want to set a default value for this field when it's displayed on the front end. (It's ok to have the default value on the admin side too, but I'm not worried about that.)
The value, however, is not a static value. It is based on the user that is currently logged in, and then some additional processing is done to get the actual value that should be the default.
So I'm using the rwmb_normalize_{field_id}_field
filter to assign $field['std']
to the proper value. That all works fine.
The problem comes in with the RW_Meta_Box->is_saved
function. When it calls raw_meta
, the value returned is an empty array (because it's a relationship field? I'm not sure). So this check in is_saved
fails:
if ( false === $value ) {
continue;
}
and this check returns true because the field is single but value is an empty array:
if (
( $single && '' !== $value )
|| ( ! $single && is_array( $value ) && [] !== $value )
) {
return true;
}
is_saved
returning true means that the $field['std'] setting is ignored because MB thinks the field has already been saved.
So, I don't know if is_saved
needs to be fixed to handle relationships better, or if there's some other method I should be using to accomplish this.
Thanks!