> */ public function ordered(): array { global $wpdb; $rows = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}abientot_service_categories ORDER BY sort_order ASC, name ASC", ARRAY_A ); return is_array( $rows ) ? $rows : array(); } public function next_sort_order(): int { global $wpdb; return (int) $wpdb->get_var( "SELECT COALESCE(MAX(sort_order), 0) + 10 FROM {$wpdb->prefix}abientot_service_categories" ); } /** * Persists the category display order. * * @param int[] $ids Category IDs in display order. */ public function reorder( array $ids ): void { global $wpdb; $position = 10; foreach ( $ids as $id ) { $id = absint( $id ); if ( $id <= 0 ) { continue; } $wpdb->update( $this->table(), array( 'sort_order' => $position, 'updated_at' => gmdate( 'Y-m-d H:i:s' ), ), array( 'id' => $id ), array( '%d', '%s' ), array( '%d' ) ); $position += 10; } } public function find_by_slug( string $slug ): ?array { return $this->find_by( 'slug', $slug ); } }