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): ?>
                
                    <tr>
                       
                    <td class="text-center"><p>
                    <a class="fancybox-frame" href="http://www.youtube.com/embed/<?php echo $event->youtubeid()->html()?>?list=PL0nBAqtSzTDp4r9kz7PqauS1SSww9O68-&enablejsapi=1&wmode=opaque&autoplay=1"><?php echo $event->name()->upper() ?></a>
                    </p></td>
                    
                    </tr>
                
                <?php endforeach ?>
    
            <?php endforeach ?>  
            
</table>

my blueprints:

title: day
pages: false
icon: youtube-play
deletable: true
fields:
  title:
    label: Day
    type:  text
    readonly: true
  events:
    label: Video
    type: structure
    fields:
      name:
        label: Name
        type: text 
      youtubeid:
        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.

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!
:smiley: