unserialize(): Error - When using custom admin column
Support › MB Admin Columns › unserialize(): Error - When using custom admin columnResolved
- This topic has 4 replies, 2 voices, and was last updated 3 months, 1 week ago by
Codog.
-
AuthorPosts
-
December 29, 2024 at 2:46 AM #47257
Codog
ParticipantHi there,
I implemented a custom admin column function following your documentation a while back and all has been working fine. But recently I noticed an "unserialize(): Error at offset 1347 of 2148 bytes" in my Query Monitor. The custom admin column displays fine and before the title as expected. If I remove this function completely the "unserialize(): Error" disappears.MY CODE:
========add_action( 'init', 'pl_add_custom_columns', 20 ); function pl_add_custom_columns() { class Pl_Custom_Admin_Columns extends \MBAC\Post { public function columns( $columns ) { $columns = parent::columns( $columns ); $position = 'before'; $target = 'title'; $this->add( $columns, '_thumbnail_id', 'Featured Image', $position, $target ); return $columns; } public function show( $column, $post_id ) { switch ( $column ) { case '_thumbnail_id': $img_url = wp_get_attachment_image_url( get_post_thumbnail_id( $post_id ), 'thumbnail' ); if( !empty( $img_url ) ) { echo '<img class="admin-featured-img" src="' . $img_url . '" alt="'.get_the_title().'" title="'.get_the_title().'" />'; } else { echo '<img class="admin-featured-img" src="'. esc_url(get_stylesheet_directory_uri()).'/img/img-fallback.svg" alt="No Featured Image" title="No Featured Image">'; } break; // More columns } } } new Pl_Custom_Admin_Columns( 'custom_post_type', array() ); }
* Note this method was used to display the featured image in the admin column because the
_thumbnail_id
uses the'type' => 'file_upload'
.Q) Is my implementation correct?
Q) Is there a better method?
Q) Is this a known bug?I look forward to your response 🙂
December 31, 2024 at 9:13 AM #47270Peter
ModeratorHello,
Do you add/upload more featured images to the field
_thumbnail_id
? Because the field typefile_upload
allows uploading multiple files/images.
You can try to use the field typesingle_image
to recheck this issue. Following the documentation
https://docs.metabox.io/fields/single-image/December 31, 2024 at 4:41 PM #47274Codog
ParticipantHi Peter,
thanks for your response. However, in my context I cannot use another field type such as thesingle_image
as this provides access to the media library popup. Myfile_upload
field is part of a frontend submission form that MUST prevent my users from accessing the media library.Are there any other work arounds or options to fix this error?
Thanks!
January 3, 2025 at 9:47 PM #47302Peter
ModeratorHello,
Can you please move the class
Pl_Custom_Admin_Columns
to a separate file and include it in the callback functionpl_add_custom_columns
as noted in the documentation?
https://docs.metabox.io/extensions/mb-admin-columns/#custom-admin-columnsI follow the documentation, use your code to show a custom admin column for the field
_thumbnail_id
but don't see that issue. Please recheck this and let me know how it goes.January 7, 2025 at 5:53 PM #47321Codog
ParticipantHi Peter,
thanks for the guidance. After some further debugging, turns out the unserialize() issue I was experiencing originated from a completely unrelated function. My apologies. -
AuthorPosts
- You must be logged in to reply to this topic.