Posted on by

Filtering a List Based on the Current Date

It’s possible to determine what records are shown using the [pdb_list] shortcode by using the “filter” attribute. If you want to show records from a range of dates, you can use the filter to determine the start and end dates for the range.

List filters are discussed in detail here. Read that page if you have not worked with list filters before.

But what if you want to show a list that is filtered according to the current date? For instance all the records from the last week or all the records from the current month? This is possible by dynamically building the shortcode instead of using it as static text in your content.

Since this requires PHP, there are a couple of ways to go. If you’re familiar with using templates or creating shortcodes, you can do it that way. Another less technical approach is to use a plugin that lets you put PHP code in your content. However you go, you will need to know some simple PHP to customize this for whatever you want to do in your case.

Here is an example of showing all the records from the last week:

And here is an example of getting all the results in the current month:

These are good examples of how to do simple date manipulations using PHP.

Using PHP Snippets

There are plugins that let you place PHP in your content which can simplify getting a little bit of code (a “snippet”) on your page. To do that, you would take the code, like one of the examples above, and place it in a snippet. Usually, you don’t need the PHP tags <?php ?> and then put the code in your page according to the instructions for the snippet plugin.

Leave a Reply
You have to agree to the comment policy.

Leave a Reply
You have to agree to the comment policy.