Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
jamio.wonders

Inline edit checkbox column set meta to 0 when unchecked

Hi,

I am using Admin Columns Pro with Toolset Types, I have created a simple checkbox custom field and in Toolset Types I have configured it to store ‘1’ if the field is checked, and when unchecked save 0 to the database. In the All Posts admin screen I have ACP setup to show the toolset field with inline editing, if I check the field then ‘1’ is saved to the database for the custom checkbox field, however I then uncheck the field all data for the field is removed from the database instead of saving a ‘0’ to the database. This is breaking some of the filters I have setup in Toolset Views as it’s looking for a ‘0’.

Are you able to fix this please?

Thanks

4 years, 9 months ago
jamio.wonders

I just want to add then when I edit the post directly and check and save then uncheck and save it is correctly placing a ‘0’ into the database, the problem is only with inline editing in ACP.

4 years, 9 months ago
Stefan van den Dungen Gronovius
Developer

Thanks for your feedback.
I was able to reproduce this issue with the Types setting.
We’ll make sure it will be changed in the next release of the Types integration.
In the meantime, you could use the following snippet to correct it for your environment.

add_filter( 'acp/editing/save_value', function ( $value, AC\Column $column ) {
	if ( $column instanceof ACA\Types\Column && $column->get_field() instanceof ACA\Types\Field\Checkbox ) {
		if ( ! $value && $column->get_field()->get( 'save_empty' ) === 'yes' ) {
			$value = '0';
		}
	}

	return $value;
}, 10, 2 );

It uses the following hook.
https://www.admincolumns.com/documentation/filter-reference/acp-editing-save_value/

4 years, 9 months ago
jamio.wonders

Thank you so much Stefan! That fixed it for me, my custom filers are now working correctly every time. I really appreciate your help with fixing this.

4 years, 9 months ago

You must be logged in to reply to this topic.