Admin Column - Date Format
Support › MB Admin Columns › Admin Column - Date FormatResolved
- This topic has 8 replies, 2 voices, and was last updated 3 years, 6 months ago by
uptwo.
-
AuthorPosts
-
October 12, 2021 at 10:00 PM #31272
uptwo
ParticipantHey,
currently I save the format of my datapicker as 'Y-m-d' (bc of filtering) and jsoptions as 'dd.mm.yy'.However, the problem is that in the admin columns 'Y-m-d' is used. I know that is because it is stored that way in the database but in my opinion is very impractical.
Would there be the possibility to implement something like:admin_columns' => [ 'dateFormat' => 'dd.mm.yy', ],
Or is there a way I haven't seen yet to take the jsoptions as admin column format?
October 12, 2021 at 10:52 PM #31274Long Nguyen
ModeratorHi,
Please refer to this tutorial to change the display another date format https://docs.metabox.io/using-two-date-formats/
Let me know how it goes.
October 13, 2021 at 4:02 PM #31292uptwo
ParticipantHey Long, thanks for your fast reply!
But that doesn't change my initial problem!
My Date Value as saved as Y-m-d in the Database.
The display for the date is saved as d.m.Y.
In the Admin Columns the Date is shown as Y-m-d (Database Format).
But i want to display the date in the admin columns as the display date (d.m.Y)! Without changing the database formatting.
I guess this isn't possible?
October 13, 2021 at 4:12 PM #31293uptwo
ParticipantSee additional screenshots:
Admin Columns Format:
https://ibb.co/Xtjg8x8Display Format:
https://ibb.co/0mVKNwNWanted Result (without changing the database format):
https://ibb.co/f4Cg3MjOctober 13, 2021 at 11:01 PM #31306Long Nguyen
ModeratorHi,
The admin column uses the helper function
rwmb_the_value
to show the field value. You can use this filter hook to change the date format when showing on the backend. For example:add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) { $value = rwmb_meta( 'date_picker', $args, $object_id ); if( is_admin() ) { $output = date( 'd F, Y', strtotime( $value ) ); } return $output; }, 11, 4 );
Admin column: https://share.getcloudapp.com/kpu6kg7g
Database: https://share.getcloudapp.com/BluDg9Y7Read more on the documentation https://docs.metabox.io/filters/#rwmb_the_value
October 13, 2021 at 11:53 PM #31309uptwo
ParticipantAbsolutely wonderful! Thank you very much for your awesome support, again and again!
October 15, 2021 at 3:55 AM #31327uptwo
ParticipantAnother Problem has occurred, now every admin column is taken from this specific field 😀
See screenshot: https://ibb.co/wyWwYpX
October 15, 2021 at 9:23 AM #31333Long Nguyen
ModeratorHi,
If you have more admin columns for other fields, you can add the condition to show for a specific field as well.
add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) { $value = rwmb_meta( 'date_picker', $args, $object_id ); if( is_admin() && $field['id'] == 'date_picker') { $output = date( 'd F, Y', strtotime( $value ) ); } return $output; }, 11, 4 );
Get the field settings from the variable
$fields
https://docs.metabox.io/field-settings/#generalOctober 15, 2021 at 5:16 PM #31335uptwo
ParticipantAnd again, thank you very much. Makes sense! You and the whole meta box team are wonderful
-
AuthorPosts
- You must be logged in to reply to this topic.