Created
April 15, 2022 02:41
-
-
Save atwellpub/07896b0f3f1da2e8c17cca48d908db81 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* | |
*/ | |
public static function get_rule_logs( $query ) { | |
if (!isset($query['rule_id']) || !$query['rule_id']) { | |
return []; | |
} | |
global $wpdb; | |
$table_name = $wpdb->prefix . "logs WHERE 1=1 "; | |
$query = 'SELECT * FROM '.$table_name; | |
$args = []; | |
if (isset($query['rule_id']) && $query['rule_id']) { | |
$query .= ' AND rule_id = %d '; | |
$args[] = $query['rule_id']; | |
} | |
if (isset($query['begin_date']) && $query['begin_date']) { | |
$query .= ' AND datetime >= %s '; | |
$args[] = $query['begin_date']; | |
} | |
if (isset($query['end_date']) && $query['end_date']) { | |
$query .= ' AND datetime <= %s '; | |
$args[] = $query['end_date']; | |
} | |
return $wpdb->get_results( $wpdb->prepare( $query , $args ) , ARRAY_A ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The difference between append and implode is more visual :)
The dummy
1 = 1
looks horrible while the implode solution is more "object-oriented", but is just a personal taste