Created
June 28, 2023 13:55
-
-
Save Pebblo/2ee371858ee4a4f7715983fe219e3459 to your computer and use it in GitHub Desktop.
Example of how to change the default order_by used in for datetimes within the EE REST API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Do not include the opening PHP tag if you already have one | |
add_filter('FHEE__Read__create_model_query_params', 'tw_ee_set_ee_rest_datetime_order_by', 10, 3); | |
function tw_ee_set_ee_rest_datetime_order_by( $model_query_params, $query_params, $model ) { | |
if($model instanceof EEM_Datetime) { | |
// Match default order_by array to compare. | |
$default_order_by['DTT_ID'] = 'ASC'; | |
// Check if the order_by currently set is the default order_by. | |
if( $default_order_by === $model_query_params['order_by']) { | |
// Order by DTT_ID => ASC so override that with DTT_EVT_Start => DESC | |
$model_query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); | |
} | |
} | |
return $model_query_params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment