I have a custom model set up and saving data successfully to its custom table.
I want to display data from that table, but if I don't have a specific $object_id to query, is there another method available to use if I want to fetch a single row based on certain criteria?
For example, the first result when the dates in a datetime column is sorted via ASC?
I'm afraid that there aren't other methods to get data from a custom table without ID. We also use the SQL query to get the data, please check this function
private static function query_get( int $object_id, string $table ): array {
global $wpdb;
$row = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM $table WHERE <code>ID</code> = %d",
$object_id
),
ARRAY_A
);
return is_array( $row ) ? $row : [];
}