Entry

Three New Content Filters in ExpressionEngine 4

by: Derek Jones on: 2/1/2018

We’ve been sharing some of ExpressionEngine’s big new features on our blog lately. But ExpressionEngine 4 also comes packed with little treats that increase your web site’s flexibility and make building sites even easier. Here are three new content filters that you can start using today!

show_expired='only'

Expiration dates are a great way to automate removal of content from your site at a specified time. (Pizza joints, I’m looking at you and your “current specials” that expired in fall of 2017…) Whether it’s a concert, a limited time offer, or an annual funding drive, expiration dates can ensure that your web site doesn’t contain stale content. And your content authors don’t have to set reminders and alarms and wake up at 2am to close entries.

But let’s say that you want to explicitly show expired content in an archive listing. Easy enough, show_expired='yes'. Ah, but things aren’t always so simple are they? Take this example of a City Events channel:

Event Entry Date Expiration Date
First Friday Art Walk 2/02/2018 5:30pm 2/02/2018 10:00pm
Local Pour Craft Beverage Tours 2/15/2018 1:30pm 2/15/2018 5:00pm
Winterfest 2/15/2018 6:00pm 2/18/2018 9:00pm

show_expired='yes' works mostly:

{exp:channel:entries channel='events' show_expired='yes'}

With this opening tag, a visitor to the archive on February 9th would see the previous weekend’s event, First Friday Art Walk.

But what about someone visiting the site on February 17th, in the middle of Winterfest? Winterfest is an open entry, dated two days ago, so it would show up too. But that’s not our intent. We don’t want a visitor in town on Saturday to think that Winterfest is over!

{exp:channel:entries channel='events' show_expired='only'}

This new filter matches our intent. Only show events that have expired. On February 17th, that means First Friday Art Walk and Local Pour Craft Beverage Tours will be listed in our archive of past events, but not Winterfest, which isn’t over yet. At 9pm on Sunday the 18th, Winterfest will automatically be included as a past event.

sticky='only'

Sticky entries ignore the sort order of your Channel Entries tag and are always listed first. This can be handy for important announcements, for keeping hot news stories on the front page, or for descriptive content that you always want visitors to see first.

Let’s say you have a variable number of “hot” news items. Some days it’s ten stories, on a slow news day there are only two. You want to make a link so your regular visitors can jump straight to the hot stories. In ExpressionEngine, you always have many options for implementation, each with subtle differences in behavior.

For example, you could use a “Featured” status and filter based on that. But statuses don’t affect the sort order, so to keep them at the top, you’d have to use a separate Channel Entries tag. That’s okay, but if the number of articles is variable and you’ve got a complex layout, it can get tricky.

Sticky is perfect in this case, but previously you’d have to “cut” the listings using limit='', which means placing that same limitation on your content authors. limit='5', instruct them to just pick 5 stories, no more no less, and their “hot stories” are fine. But if they pick more than 5, then the excess won’t show up. If they pick fewer than 5, then normal stories get included with the “hot” ones.

With this new filter:

{exp:channel:entries channel='news' sticky='only'}

Now you can create a listing that only contains your must-read content, without setting limits on your content authors.

search:numeric_field=''

The last new unsung parametric hero of ExpressionEngine 4 is an update to the venerable search:field='' parameter. For numeric fields, you’ve always been able to use basic comparison operators. To show items that are $10 or less: search:price='<=10'. ExpressionEngine 4 expands on this by allowing you to specify ranges.

{!-- show me Middle Schoolers --}
{exp:channel:entries channel='students' search:grade='>5|<9'}

Now the filter will show all students from grades 6, 7, and 8.

This also works for custom date fields. Since date fields are stored in Unix time, you can perform numeric range checks just as easily.

{!-- show everyone who signed up to take their ACT from February through April 2018 --}
{exp:channel:entries channel='students' search:act_date='>1517443200|<1525132800'}

I find unixtimestamp.com helpful to define timestamps, and I use ExpressionEngine template comments to remind myself of the human readable date.

And there you have it. Three simple but powerful filtering options now available in ExpressionEngine 4. We hope they help you solve challenges more easily than ever!

.(JavaScript must be enabled to view this email address) or share your feedback on this entry with @ellislab on Twitter.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases