Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created April 14, 2022 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atwellpub/37a952f0cbe9c8a07e4db6417883c48b to your computer and use it in GitHub Desktop.
Save atwellpub/37a952f0cbe9c8a07e4db6417883c48b to your computer and use it in GitHub Desktop.
Draft method of retrieving logs from database
<?php
/*
*
*/
public function get_special_logs( $query ) {
if (!isset($query['special_id']) || !$query['special_id']) {
return [];
}
global $wpdb;
$count = 0;
$table_name = $wpdb->prefix . "special_logs";
$query = 'SELECT * FROM '.$table_name;
if (isset($query['special_id']) && $query['special_id'] && ++$count) {
$query .= (!$count ? ' WHERE ' : ' AND ' ) . ' special_id = "'.$query['special_id'].'" ';
}
if (isset($query['begin_date']) && $query['begin_date'] && ++$count) {
$query .= (!$count ? ' WHERE ' : ' AND ' ) . ' datetime >= "'.$query['begin_date'].'" ';
}
if (isset($query['end_date']) && $query['end_date'] && ++$count) {
$query .= (!$count ? ' WHERE ' : ' AND ' ) .' datetime <= "'.$query['end_date'].'" ';
}
return $wpdb->get_results( $query , ARRAY_A );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment