@@ -671,24 +671,26 @@ protected static function get_join_parts( string $join_table, string $join_condi
671671 * Gets all models by a column.
672672 *
673673 * @since 3.0.0
674+ * @since 3.1.1 Added the $order_by parameter.
674675 *
675676 * @param string $column The column to get the models by.
676677 * @param mixed $value The value to get the models by.
677678 * @param string $operator The operator to use.
678679 * @param int $limit The limit of models to return.
680+ * @param string $order_by The order by clause to use.
679681 *
680682 * @return mixed[] The models, or an empty array if no models are found.
681683 *
682684 * @throws InvalidArgumentException If the column does not exist.
683685 */
684- public static function get_all_by ( string $ column , $ value , string $ operator = '= ' , int $ limit = 50 ): ?array {
686+ public static function get_all_by ( string $ column , $ value , string $ operator = '= ' , int $ limit = 50 , string $ order_by = '' ): ?array {
685687 [ $ value , $ placeholder ] = self ::prepare_value_for_query ( $ column , $ value );
686688
687689 $ operator = strtoupper ( $ operator );
688690
689691 $ database = Config::get_db ();
690692 $ results = [];
691- foreach ( static ::fetch_all_where ( $ database ::prepare ( "WHERE %i {$ operator } {$ placeholder }" , ...array_filter ( [ $ column , $ value ], static fn ( $ v ) => null !== $ v ) ), $ limit , ARRAY_A ) as $ task_array ) {
693+ foreach ( static ::fetch_all_where ( $ database ::prepare ( "WHERE %i {$ operator } {$ placeholder }" , ...array_filter ( [ $ column , $ value ], static fn ( $ v ) => null !== $ v ) ), $ limit , ARRAY_A , $ order_by ) as $ task_array ) {
692694 if ( empty ( $ task_array [ static ::uid_column () ] ) ) {
693695 continue ;
694696 }
0 commit comments