How to sort sites by their structure fields?

Hi there!
I’m trying to sort the event of the “grandchildren” of a page alphabetically by their names.
This code isn’t working for me. It only shows the list sorted by their creation dates.

Note: There is only one event for every $day

(Please ask me if you don’t understand what I mean) :wink:

<table class="number-list">
            <?php $day = $pages->filterBy('template', 'calendar')->children()->children(); foreach($day as $video): ?>
                <?php foreach ($video->events()->toStructure()->toStructure()->sortBy('name', 'asc') as $event): ?>
                    <td class="text-center"><p>
                    <a class="fancybox-frame" href="<?php echo $event->youtubeid()->html()?>?list=PL0nBAqtSzTDp4r9kz7PqauS1SSww9O68-&enablejsapi=1&wmode=opaque&autoplay=1"><?php echo $event->name()->upper() ?></a>
                <?php endforeach ?>
            <?php endforeach ?>  

my blueprints:

title: day
pages: false
icon: youtube-play
deletable: true
    label: Day
    type:  text
    readonly: true
    label: Video
    type: structure
        label: Name
        type: text 
        label: Link
        type: text

The problem here is that you want to get all the events of all structure fields and then sort them.

  1. question: if there is only one event per page, why do you use a structure field for it instead of just two standard fields?

  2. to achieve what you want with your current setup, you would have to create a structure field from all structure field of all pages. See this post for an example how to achieve this.

1 Like

Thank you for your quick reply!

  1. I’m using the calendar board from molocLab. This gives me structure fields when creating a new event (even though I only need one event per day)

  2. seems promising - gonna have a look :slight_smile:

YAY! It worked for me! Thank you @texnixe!