Sort doesn't work if not logged in

Hello again.

On my site, if the user is logged in, the sort works for the shortcode-generated list of items. However, if the user is not logged in, it does not work. How do I fix it?

This is my site:
https://blmohp.sewanee.edu/page/people

This is my code:

<div class="preview-block clearfix">[items item_set=8 num=0 sort=foaf:lastName]</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', async () => {
    const items = document.querySelectorAll('.resource.item');
    
    for(let item of items) {
        const itemThumb = item.querySelector('.resource.item a').firstChild;
        itemThumb.classList.add('item-thumbnail');

        // Extract the item ID from the title link
        const idMatch = item.querySelector('h4 a').getAttribute('href').match(/\/item\/(\d+)/);
        if (idMatch) {
            const itemID = idMatch[1];
            
            // Fetch Media-IDs for audio-visual documents asynchronously
            let mediaID;
            try {
                const response = await fetch(`/api/media?item=${itemID}`);
                const mediaItems = await response.json();
                for(let mediaItem of mediaItems) {
                    if (mediaItem['o:ingester'] === 'youtube') {
                        mediaID = mediaItem['o:id'];
                        break;
                    }
                }
            } catch (error) {
                console.error('Failed to fetch media items:', error);
                // Handle error appropriately
            }   
            
            if (mediaID) {
                // Create Button See the Interview
                const buttonSee = document.createElement('a');
                buttonSee.setAttribute('href', '/media/' + mediaID);
                buttonSee.classList.add('button-see');
                buttonSee.innerHTML = '<img src="https://omeka-s.sewanee.edu/files/asset/c3363c21b14027aaa6c0f7a9d07580da4f8359c7.png" alt="Button See the Interview">';
                
                // If a media item with a YouTube ingester was found, append the See the Interview button
                const itemButtons = item.querySelector('.item-buttons') || document.createElement('div');
                itemButtons.classList.add('item-buttons');
                itemButtons.appendChild(buttonSee);
                item.appendChild(itemButtons);
            }

            // Create Button Learn More
            const buttonLearn = document.createElement('a');
            buttonLearn.setAttribute('href', '/item/' + itemID);
            buttonLearn.classList.add('button-learn');
            buttonLearn.innerHTML = '<img src="https://omeka-s.sewanee.edu/files/asset/40ab43f8a04a70f61edd9cb5dfa1afb2f232f52e.png" alt="Button Learn More">';

            // Append Learn More button regardless of the mediaID existence
            const itemButtons = item.querySelector('.item-buttons') || document.createElement('div');
            itemButtons.classList.add('item-buttons');
            itemButtons.appendChild(buttonLearn);
            item.appendChild(itemButtons);
        }
    }
}); 
</script>
1 Like

I don’t see a “last name” field on those items when I look at them (not logged in, of course).

Do you have those values marked as private, maybe? If they’re private they aren’t available for sorting either, to avoid revealing information about the values even when they aren’t directly displayed.

If that’s the case you may want to make those values public and instead use something like the Hide Properties module to just hide them from the public pages. That way they’ll be usable for sorting but still not visible to public visitors.

Thanks. I didn’t realize the “Hide Properties” module was different than just making them private. On a previous project, having the “lastName” private still let me sort them within a Faceted Browse page, so I thought it would work for this too.