public function getArchivedBlogPosts($year, $month = null, $day = null)
    {
        $query = $this->getBlogPosts()->dataQuery();

        $stage = $query->getQueryParam('Versioned.stage');

        if ($stage) {
            $stage = '_' . $stage;
        }

        $query->innerJoin(
            DataObject::getSchema()->tableName(BlogPost::class),
            sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)
        );

        $conn = DB::get_conn();

        // Filter by year
        $yearCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%Y');
        $query->where(sprintf('%s = \'%04d\'', $yearCond, Convert::raw2sql($year)));

        // Filter by month (if given)
        if ($month) {
            $monthCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%m');
            $query->where(sprintf('%s = \'%02d\'', $monthCond, Convert::raw2sql($month)));

            if ($day) {
                $dayCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%d');
                $query->where(sprintf('%s = \'%02d\'', $dayCond, Convert::raw2sql($day)));
            }
        }


        return $this->getBlogPosts()->setDataQuery($query);
    }
public function getArchivedBlogPosts($year, $month = null, $day = null)
    {
        $query = $this->getBlogPosts()->dataQuery();

        $stage = $query->getQueryParam('Versioned.stage');

        if ($stage) {
            $stage = '_' . $stage;
        }

        $query->innerJoin(
            DataObject::getSchema()->tableName(BlogPost::class),
            sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)
        );

        $conn = DB::get_conn();

        // Filter by year
        $yearCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%Y');
        $query->where(sprintf('%s = \'%04d\'', $yearCond, Convert::raw2sql($year)));

        // Filter by month (if given)
        if ($month) {
            $monthCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%m');
            $query->where(sprintf('%s = \'%02d\'', $monthCond, Convert::raw2sql($month)));

            if ($day) {
                $dayCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%d');
                $query->where(sprintf('%s = \'%02d\'', $dayCond, Convert::raw2sql($day)));
            }
        }


        return $this->getBlogPosts()->setDataQuery($query);
    }
public function getArchivedBlogPosts ( $ year , $ month = null , $ day = null ) { $ query = $ this -> getBlogPosts ( ) -> dataQuery ( ) ; $ stage = $ query -> getQueryParam ( 'Versioned.stage' ) ; if ( $ stage ) { $ stage = '_' . $ stage ; } $ query -> innerJoin ( DataObject :: getSchema ( ) -> tableName ( BlogPost :: class ) , sprintf ( '"SiteTree%s"."ID" = "BlogPost%s"."ID"' , $ stage , $ stage ) ) ; $ conn = DB :: get_conn ( ) ; // Filter by year $ yearCond = $ conn -> formattedDatetimeClause ( '"BlogPost"."PublishDate"' , '%Y' ) ; $ query -> where ( sprintf ( '%s = \'%04d\'' , $ yearCond , Convert :: raw2sql ( $ year ) ) ) ; // Filter by month (if given) if ( $ month ) { $ monthCond = $ conn -> formattedDatetimeClause ( '"BlogPost"."PublishDate"' , '%m' ) ; $ query -> where ( sprintf ( '%s = \'%02d\'' , $ monthCond , Convert :: raw2sql ( $ month ) ) ) ; if ( $ day ) { $ dayCond = $ conn -> formattedDatetimeClause ( '"BlogPost"."PublishDate"' , '%d' ) ; $ query -> where ( sprintf ( '%s = \'%02d\'' , $ dayCond , Convert :: raw2sql ( $ day ) ) ) ; } } return $ this -> getBlogPosts ( ) -> setDataQuery ( $ query ) ; }
Returns BlogPosts for a given date period.

@param int $year
@param null|int $month
@param null|int $day

@return DataList
Returns BlogPosts for a given date period .