public static find_one_by ( string $property, string $value ) : false | self | ||
$property | string | |
$value | string | |
return | false | self |
public static function find_one_by($property, $value)
{
global $wpdb;
// Escape the value
$value = esc_sql($value);
// Get the table name
$table = static::get_table();
// Get the item
$obj = $wpdb->get_row("SELECT * FROM `{$table}` WHERE `{$property}` = '{$value}'", ARRAY_A);
// Return false if no item was found, or a new model
return $obj ? static::create($obj) : false;
}