Timber\PostGetter::get_post PHP Метод

get_post() публичный статический Метод

public static get_post ( mixed $query = false, string | array $PostClass = '\Timber\Post' ) : array | boolean | null
$query mixed
$PostClass string | array
Результат array | boolean | null
    public static function get_post($query = false, $PostClass = '\\Timber\\Post')
    {
        // if a post id is passed, grab the post directly
        if (is_numeric($query)) {
            $post_type = get_post_type($query);
            $PostClass = PostGetter::get_post_class($post_type, $PostClass);
            $post = new $PostClass($query);
            // get the latest revision if we're dealing with a preview
            $posts = PostCollection::maybe_set_preview(array($post));
            if ($post = reset($posts)) {
                return $post;
            }
        }
        $posts = self::get_posts($query, $PostClass);
        if ($post = reset($posts)) {
            return $post;
        }
    }

Usage Example

Пример #1
0
 /**
  * Get post.
  * @api
  * @param mixed   $query
  * @param string|array  $PostClass
  * @return array|bool|null
  */
 public static function get_post($query = false, $PostClass = 'Timber\\Post')
 {
     return PostGetter::get_post($query, $PostClass);
 }