Get by a key/val
Note: This only works with custom meta fields, not core fields
@param string $key
@param mixed $val
@param string $compare
@param mixed $args
@param bool $load_terms
@return array
193714
public static function getPairsBy($key, $val, $compare = '=', $args = array())
    {
        $instance = Post\Factory::create(get_called_class());

        global $wpdb;
        if (in_array($key, static::getCoreFieldKeys())) {
            // Using a core field
            $sql = sprintf(
                "SELECT p.ID, p.post_title
                FROM $wpdb->posts p
                WHERE p.post_type = %s
                AND (p.post_status = 'publish')
                AND %s %s %s
                ORDER BY p.ID ASC",
                '%s',
                $key,
                $compare,
                '%s'
            );
            $prepared_sql = $wpdb->prepare($sql, $instance->getPostType(), $val);
        } else {
            // Number fields should be compared numerically, not alphabetically
            // Of course, this currently requires you to use type=number to achieve numeric sorting
            $fields = $instance->getFields();
            $field_is_numeric = ($fields[$key]['type'] === 'number');

            // Using a meta field
            $sql = sprintf(
                "
                SELECT p.ID, p.post_title
                FROM $wpdb->postmeta pm
                INNER JOIN $wpdb->posts p
                ON p.ID = pm.post_id
                WHERE p.post_type = %s
                AND (p.post_status = 'publish')
                AND pm.meta_key = %s
                AND %s %s %s
                ORDER BY p.ID ASC
                ",
                '%s',
                '%s',
                ($field_is_numeric) ? 'CAST(pm.meta_value AS DECIMAL)' : 'pm.meta_value',
                $compare,
                '%s'
            );
            $prepared_sql = $wpdb->prepare($sql, $instance->getPostType(), $key, $val);
        }
        $results = $wpdb->get_results($prepared_sql);
        $post_ids = Collection::pluck($results, 'ID');
        if (!Arr::iterable($args)) {
            if (!Arr::iterable($results)) {
                return array();
            }
            
            return array_combine(
                $post_ids,
                Collection::pluck($results, 'post_title')
            );
        }

        if (array_key_exists('post__in', $args)) {
            $args = (is_array($args)) ? $args : array_map('trim', explode(',', $args));
            $args['post__in'] = array_merge($args['post__in'], $post_ids);
        } else {
            $args['post__in'] = $post_ids;
        }

        // Need to use args? Call getBy.
        $records = static::getBy($key, $val, $compare, $args, false);
        if (!Arr::iterable($records)) {
            return array();
        }
    
        return array_combine(
            Collection::pluck($records, 'ID'),
            Collection::pluck($records, 'post_title')
        );
    }
1308342
public static function loadModuleIfAbsent($mod, $version = null, $compare = '>=')
    {
        if (!extension_loaded($mod)) {
            if (!get_cfg_var('enable_dl')) {
                return false;
            }
            if (!@dl(basename($mod) . '.so')) {
                return false;
            }
        }
        if (!$version) {
            return true;
        }
        try {
            $ext = new \ReflectionExtension($mod);
            return version_compare($ext->getVersion(), $version, $compare);
        } catch (\ReflectionException $e) {
            return false;
        }
    }
1072441
public function getComparison($key)
    {
        if (isset($this->map[$key])) {
            return $this->map[$key]->getComparison();
        }

        return null;
    }
372366
protected function _buildAttr($key, $val)
    {
        $return = null;
        if (!empty($val) || $val === '0' || $key === 'value') {
            $return = ' ' . $key . '="' . $val . '"';
        }

        return $return;
    }
899746
public function walkComparison(Comparison $comparison) : Expr
    {
        switch ($comparison->getOperator()) {
            case Comparison::EQ:
            case Comparison::GT:
            case Comparison::GTE:
            case Comparison::IN:
            case Comparison::IS:
            case Comparison::LT:
            case Comparison::LTE:
            case Comparison::NEQ:
            case Comparison::NIN:
                $method = self::$operatorMethods[$comparison->getOperator()];

                return $this->builder->expr()
                    ->field($comparison->getField())
                    ->{$method}($this->walkValue($comparison->getValue()));

            case Comparison::CONTAINS:
                $value = $this->walkValue($comparison->getValue());

                return $this->builder->expr()
                    ->field($comparison->getField())
                    ->equals(new Regex($value, ''));

            default:
                throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
        }
    }
1351980
function get($key,$args=NULL) {
		if (is_string($val=$this->ref($key,FALSE)) && !is_null($args))
			return call_user_func_array(
				array($this,'format'),
				array_merge(array($val),is_array($args)?$args:array($args))
			);
		if (is_null($val)) {
			// Attempt to retrieve from cache
			if (Cache::instance()->exists($this->hash($key).'.var',$data))
				return $data;
		}
		return $val;
	}
1238163
public function ltFieldValidator($val, string $compareField): bool
    {
        $maxVal = $this->getByPath($compareField);

        if ($maxVal === null) {
            return false;
        }

        return Validators::lt($val, $maxVal);
    }
109233
public function get($_, $assoc_args)
    {
        $this->init_args(func_get_args());
        list($key) = $_;

        $env = $this->get_env_for_read_or_fail();

        if (is_null($value = $env->get($key))) {
            WP_CLI::error("Key '$key' not found.");
        }

        WP_CLI::line($value);
    }
213980
public function findBy(string $property, $value, string $comparisonOp = 'eq'): self
    {
        return $this->filterBy($property, $value, $comparisonOp);
    }
804213
public function getByCondition($key, $comparator, $value = null)
    {
        $query = $this->createQuery();
        $conditionSet = $query->buildAndSet([$key, $comparator, $value]);
        return $this->getByConditionSet($conditionSet);
    }
1165463
protected function applyEquality($comparison, $query, $field, $input)
	{
		// Make SQL safe values
		$safe_field = $this->makeSafeField($field);
		$safe_input = $input  == '' ?
			'NULL' : DB::connection()->getPdo()->quote($input);

		// Different engines have different APIs
		switch(DB::getDriverName())
		{
			case 'mysql': return $this->applyMysqlEquality(
					$comparison, $query, $safe_field, $safe_input);
			case 'sqlite': return $this->applySqliteEquality(
					$comparison, $query, $safe_field, $safe_input);
            case 'sqlsrv': return $this->applySqlServerEquality(
					$comparison, $query, $safe_field, $safe_input);
        }
	}
875921
public function load($key, &$loaded) {
    $file = $this->getFile($this->getKey($key));
    if ($this->validate($file)) {
      $loaded = TRUE;
      
      return $this->direct ? $file : $file->getContents();
    }
    $loaded = FALSE;
  }
951335
private static function _getValueByKeyWithDefault($key,array $args, $default = null) {
        //使用方法
        list($temp, $def) = Str::explode($key, ' ', 2, $default);
        $temps  = explode(':', $temp, 2);
        $oldKey = $temps[0];
        $newKey = end( $temps );
        return array(
            $newKey,
            array_key_exists($oldKey, $args) ? $args[$oldKey] : $def,
            $oldKey
        );
    }
1061784
function load($key,$val) {
		if ($found=$this->find($key,$val)) {
			$this->id=$found[0]->id;
			return $this->item=$found[0]->item;
		}
		$this->reset();
		return [];
	}
83780
public static function getOneByMultiple($conditions, $args = array(), $load_terms = true)
    {
        $default_args = array('numberposts'=>1);
        $args = array_merge($args, $default_args);
        $results = self::getByMultiple($conditions, $args, $load_terms);
        return (Arr::iterable($results))
            ? current($results)
            : null;
    }
943361
public function walkComparison(Comparison $comparison)
    {
        $field = $comparison->getField();
        $value = $comparison->getValue()->getValue(); // shortcut for walkValue()

        if (isset($this->classMetadata->associationMappings[$field]) &&
            $value !== null &&
            ! is_object($value) &&
            ! in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) {

            throw PersisterException::matchingAssocationFieldRequiresObject($this->classMetadata->name, $field);
        }

        return $this->persister->getSelectConditionStatementSQL($field, $value, null, $comparison->getOperator());
    }
208189
public function lteFieldValidator($val, string $compareField): bool
    {
        $maxVal = $this->getByPath($compareField);

        if ($maxVal === null) {
            return false;
        }

        return Validators::lte($val, $maxVal);
    }