Added the possibility to split date range values#17
Conversation
This will allow to query more effectively between dates. Props to @rasmustaarnby
|
Some notes:
Let me know your thoughts. |
jtsternberg
left a comment
There was a problem hiding this comment.
This isn't a repo I have access to, but here's a quick review.
- Should the split_date_range arg be set to true as default?
- Should be removed the default meta_key and meta_value in DB which is in json when the split_date_range is set to true?
- no, because backwards-compatibility should be maintained
- Probably not a bad idea
|
I can merge when @jtsternberg is approving with what he sees for this. |
Co-authored-by: Justin Sternberg <me@jtsternberg.com>
Co-authored-by: Justin Sternberg <me@jtsternberg.com>
|
Thank you @jtsternberg for the quick review and comments. When possible can you give it another review? Again thank you both for the quick reply |
Unfortunately I can't remove the 2. as the daterangepicker js is using it to populate the field value on load. |
RubenMartins
left a comment
There was a problem hiding this comment.
@jtsternberg this is not correct, can you please let me know how to accomplish the class call to CMB2_Field?
Any updates on this please? |
|
@RubenMartins try this: function save_split_date_range( $field_id, $updated, $action, $cmb2_field ) {
if ( ! $updated || 'repeatable' === $action || ! $cmb2_field->args( 'split_date_range' ) ) {
return;
}
$start_field = $cmb2_field->get_field_clone( array(
'id' => $field_id . '_start',
) );
$end_field = $cmb2_field->get_field_clone( array(
'id' => $field_id . '_end',
) );
if ( $action === 'removed' ) {
$start_field->remove_data();
$end_field->remove_data();
return;
}
$value = json_decode( $cmb2_field->value, true );
if ( is_array( $value ) ) {
$value = array_map( 'sanitize_text_field', $value );
$start_field->update_data( $value['start'] );
$end_field->update_data( $value['end'] );
}
} |
Replace the use of direct update_meta to set functions from cmb2 update_data() and remove_data()
Thank you @jtsternberg this is way better. When possible please review the pr again. |
This will allow to query more effectively between dates.
Props to @rasmustaarnby #9
Can you review this @jtsternberg please?