Timber\PostGetter::query_posts PHP Method

query_posts() public static method

public static query_posts ( mixed $query = false, string | array $PostClass = '\Timber\Post' ) : PostCollection | QueryIterator
$query mixed
$PostClass string | array
return PostCollection | QueryIterator | QueryIterator
    public static function query_posts($query = false, $PostClass = '\\Timber\\Post')
    {
        if ($type = self::get_class_for_use_as_timber_post($query)) {
            $PostClass = $type;
            if (self::is_post_class_or_class_map($query)) {
                $query = false;
            }
        }
        if (is_object($query) && !is_a($query, 'WP_Query')) {
            // The only object other than a query is a type of post object
            $query = array($query);
        }
        if (is_array($query) && count($query) && isset($query[0]) && is_object($query[0])) {
            // We have an array of post objects that already have data
            return new PostCollection($query, $PostClass);
        } else {
            // We have a query (of sorts) to work with
            $tqi = new QueryIterator($query, $PostClass);
            return $tqi;
        }
    }

Usage Example

Example #1
0
 /**
  * @param mixed   	$query
  * @param string 	$post_class
  */
 public function __construct($query = false, $post_class = '\\Timber\\Post')
 {
     $this->userQuery = $query;
     $this->queryIterator = PostGetter::query_posts($query, $post_class);
     $posts = $this->queryIterator->get_posts();
     parent::__construct($posts, $post_class);
 }
All Usage Examples Of Timber\PostGetter::query_posts