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 ); | |
} |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice catch on 13-15, I was fatigued and missed that!
I'm still not sold on the implode versus append. I'm not sure there are savings.
Here's the current draft. I am about to bake in offset, limits, orderby and order direction.