Manual sorting only works after actually manual sorting

Why sometimes filterBy('sort') only works after actually sorting images by hand?

When I open a post which I prepared in the filesystem in the panel the order of the images already is correct in alphanummeric order. But I have a lot of posts whose images have to be rearranged, so I desiced to output them in each post with filterBy('sort'). Now I believe – not quit sure – this order only works if I actually manipulate the order by drag’n’drop so that the filter works.
Do you understand my problem?

Is thera lika a fallback for filterBy('sort')?
Or how can I improof this?

Yes, the sort field is only added to a file’s metadata file when at least one of the files is actually rearranged in the Panel. Otherwise, this field remains empty (or doesn’t even exist).

Also, I’m not sure what you want to do with filterBy('sort'), only filter files that have a value in the sort field?

Okay. I understand.

As you may remember, I’m working on a site for a gallery :slight_smile:
I’m dealing with round about 1000 images, separated in posts (exhibitions). Now mostly the alphanummeric order is fine, but every 10th post or so, the images have to be rearranged.
So I generally set the template to filter the images by sort.
Bad Idea?

Images without the sort value will be desplayed but sometimes they behave strange like loosing their captions. I did not made a propper study, but It’s kinda unsettling.

Additional question: If I later add a picture to a manually sorted gallery, it does not automatically receive the sort value, does it? How does the filter react then?

No, unless you run a hook after file upload to make sure that the image gets a sorting number.

Do I understand you correctly that the purpose of your filter is to only get images with a sorting number? Somehow this filter doesn’t make sense to me if you also want to fetch images without a sorting number. Why then the filter if all images should have a sorting number anyway? Maybe I’m missing something.

Oh dear, I feel so stupid.
I meant sortBy not filterBy.
I’m so sorry. :dotted_line_face:

Not clear is what happens, wenn sortBy is not possible because sort is missing. Is there no fallback? Or may @max say, this is the way?

Yep.