Question

I have several keywords (1~3 words) stored in <MTEntryKeywords> field separated by commas. I want to take out the first keyword from MTEntryKeywords.

Example 1:

In the Keywords field I have entered: gadgets,phone,apple,

Want to display: gadgets

Example 2:

In the Keywords field I have entered: food,coffee,apple,

Want to display: food

Any ideas?

Was it helpful?

Solution

This is untested, but something like this should do the trick (assuming you're using a recent enough version of MT)

<mt:entrykeywords regex_replace="/^([^,]+)(,.*)?$/","$1">

Basically, the regular expression there is saying "keep only everything up to, but not including, the first comma".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top