Sort asset listing by metadata field


(Steven) #1

Hi,

I have a list of news articles currently ordered by published date. I want to introduce a way of promoting an article to the top of the list for a few days.

I have created a new checkbox metadata field called “Promote”.

I want to change the sort order to metadata “Promote” first, then “published date” second.

If I change the default sorting order to “Promote” it just seems to randomize the results.

Any help getting this fixed would be hugely appreciated.

image


(Harinder Singh) #2

Sort the news articles by published date as default.

You can use the search page asset to search and list the promote item on top of the asset listing. It will be easy to control both the layouts.

Otherwise, you can also achieve it by SSJS without Asset listing and search page.


(Lisa) #3

Hi,

Rather than using a metadata sort field, you can create a ‘Sorting by Asset Keyword Value’ option to sort by two keywords at once using keyword replacements, something like:

%asset_metadata_Promote^eq:Yes:A {asset_published_date}:B {asset_published_date}%

Which will use “A 2023-07-05” or “B 2023-07-05” for the sort value.

Cheers,
Lisa


(Steven) #4

Hi @LisaB
I’ve tried to implement your suggestion but I must be missing something as its not affecting the list as expected.

I’ve added the “Sorting by Asset Keyword Value” you posted.

I’ve changed the settings below to look for this new sorting option:

But as you can see from the screenshot below, the “promoted” article shows in second place.

Can you spot where I’ve went wrong?

Many thanks for your help.
Steven


(Steven) #5

I’ve made progress but I still have a problem:

I can get the promoted articles at the top of the list now. I updated the metadata field so its a Yes No option.

The problem now seems to be “how do i order the rest of the articles below by the date published?” ` It seems to be random.

Any help would be appreciated.

Thanks


(Nic Hubbard) #6

I would just create two asset listings. The first would have a root node looking at the “promoted” folder. The second asset listing would look at all the assets, and exclude the “promoted” root node. Then nest both of these asset listings into a page.

When you want to promote an asset, just link it into the promoted folder. Then remove when you don’t want it promoted.


(Lisa) #7

Hi Steven, try printing out the keyword that you’re sorting by as part of the list item in the Default Format - you can easier see if it’s doing what you’re after.

Alternatively, you could use Asset Grouping to list the promoted ones first. Group by keyword or metadata field (I usually use keyword since it’s easier to update if you want to change how it functions later on, rather than deleting and adding a different grouping).


(Steven) #8

Thanks, everyone, I used your Asset grouping solution @LisaB.

Works a treat.

Ta
S