Filtering a collection by it's unique year in a date structure
  • I would like to filter a collection by it's unique year in a date field. I am using vae():


    <? $entries = vae('diary',array('unique'=>date('Y',entry_date)); ?>


    This results in an error though. I basically need an array of the years so that I can do some foreach looping.

  • 1 Answer sorted by
  • Vae can't perform that uniqueness check as part of the database engine, so you'll need to do it in PHP.

    Something like:
    foreach (vae('diary') as $entry) {
    $year = date('Y', $entry->entry_date);
    if ($year != $prev_year) {
    // do something
    }
    $prev_year = $year;
    }


    Would that work? Also, if you're making archive links, be sure to check out <v:date_selection> as a possible resource as well.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion