WordPress\ORM\BaseModel::find_one_by PHP 메소드

find_one_by() 공개 정적인 메소드

Find a specific model by a given property value.
public static find_one_by ( string $property, string $value ) : false | self
$property string
$value string
리턴 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;
    }