Support Forum
Support › MB Custom Table › Custom Tables along with Show Hide extensionResolved
Hi,
I using the "MB Custom Table" extension along with the "Meta Box Show Hide" extension.
From my experience, it doesn't integrate as expected.
Let me describe my situation:
First I'm registering a meta box that outputs a single taxonomy field called "type", which has 3 terms to choose from.
There are 3 more meta boxes registered, each one associated with each term. The meta boxes are shown only when the associated term is selected (with the 'show' argument of the meta box).
Also, each meta box is associated with a custom table.
My problem is, even though the other meta boxes are hidden, their values are saved in the custom table. It creates a row for that post in each custom table of each meta box with empty values (or default values that some fields there have).
Is it possible to ignore the saving process when the other meta boxes are hidden?
Tried to use the Include Exclude extension too, but I don't want to make the users click on save and then fill up the meta box that will show after the page loads.
Thank you for your help!
Hi Aharon,
Meta Box does not support saving the empty value to the database, custom table or default table wp_postmeta
. If you set the default value for the field, it will save that value to the database even the meta box/field is hidden. You can use the extension MB Include Exclude to prevent saving the default value.
Hi Long,
Thank you for your answer.
I managed to solve the issue indeed with the Include Exclude extension, using the custom callback: I'm showing all the meta boxes when it's the 'post-new.php' page, and after saving it's showing only one of the meta boxes based on the user's choice. And of course, it doesn't make redundant rows in the other tables 🙂
That's how my custom callback looks like:
public static function include_meta_box( $meta_box ) {
global $pagenow;
$type_selected = absint( $_POST['type'] ?? 0 );
return 'post-new.php' === $pagenow || $type_selected === $meta_box['include']['type'];
}
Thanks for sharing your solution.