Sharing what’s coming up helps us see important dates and deadlines, so we can manage events better. Take the upcoming events as an example. Let's use Meta Box and Bricks to make it happen!
Video Version
Before Getting Started
This is the rule: just events with the end date after the current day could be displayed in the section. Day by day, if it passes the end date of any event, those events will automatically disappear from the page.
Assume that today is December 8th.
We will filter and display the events that are either ongoing or scheduled for the future. This means that an event with an end date beyond December 8th will be shown on the page.
For some basic event details, I’ll create some custom fields. The start date and the end date as well as will be used for that filter. And in this case, each event will be a post of a custom post type.
Here's what we'll use:
- Meta Box plugin: to have a framework to create a custom post type and custom fields for the events. You can install it directly from wordpress.org;
- MB Custom Post Type: to create a custom post type for the events;
- Meta Box Builder: to have a UI on the backend to create the custom fields visually;
And, I use Bricks to build the page.
Now, let’s start!
Create a New Post Type
Go to Meta Box > Post Types to create a new post type for the events.
After publishing, you’ll see a new menu. It’s your post type.
Create Custom Fields
Each event may have some subsidiary information. Then, we should use custom fields to store them. I have some typical ones for this practice.
Two of them, the start date and end date should be must-have items since they will be used for the filter.
Now, go to Meta Box > Custom Fields to create them.
Choose the Date Picker field type for the start and end date of the event.
To display the date on the management dashboard for easy comparison with the results, turn on the button like in the image below. This setting is available only when enabling the MB Admin Columns extension. This extension is just optional, so I did not mention it at the beginning.
After creating all the needed fields, go to the Settings tab > choose Location as Post type > select Event to apply these fields to this post type.
Now, in the post editor, you will see the created custom fields.
Just input data into them.
Here are some posts that I created for example:
The start date and the end date are shown as admin columns. You may want to see these ones once again in the end to easily compare with the ones displayed on the page.
Display All Events on the Page
Now, choose a place then edit a page with Bricks to add the section. I will display all the events along with their information first.
First, select a Section element.
Next, add a Heading element, and name the title.
In the Container element inside the section, select the Div element to contain the event’s information.
Then, to get all posts in the Event post type, enable the Use query loop button. In the Query section, choose the Type as Posts. And, choose the post type you want to get data from in the Post type section.
Now, let’s add some elements to get detailed information of the events.
For the image of the event, choose the Image element. Since these images are the featured image of the post, click the Select dynamic data icon and choose the Featured Image option.
As you can see, the image is displayed in the preview.
Next, add the Post Title element for the event title.
Now, I want to display the start date, end date, and location along with icons, so choose the Icon Box element instead of normal text.
You can style, and choose any icon as you want.
As this information is saved in custom fields created with Meta Box, we’ll use the Select dynamic data, and then choose the corresponding fields.
As a result, you’ll see a date from the Start Date field displayed immediately.
Do the same with the end date and location. Just duplicate the Icon Box element for saving time, then change the corresponding information.
We’ve just finished getting all the posts in the event post type. Note that I specifically mentioned "all the posts".
To style this section, choose each element and change its settings.
Look at this picture, you can see all the events shown on the frontend with styling.
To display only the upcoming events, we need a custom query to filter those posts. Let’s move to the next step.
Query to Show the Upcoming Events
It’s great when Bricks supports creating any custom query on the screen. So in the page editor with Bricks, go back to the Query section of the div, look for the Meta Query section, and add a meta query.
We should compare the end date with the current date. If the events have the end date after the current date, they could be displayed. Let’s set the condition like this:
In there:
- In the Meta key box, enter the ID of the field named End Date.
- In the Meta Value box, add the current date with the
{current_date:Y-m-d}
format. - In the Compare box, choose the Greater than or equal option to get the events that have the end date after the current date.
That’s all for the condition!
On the frontend, just events have the end date after the current day, which I marked at the beginning could be displayed.
Last Words
We've walked through all the necessary steps to show upcoming events using Meta Box and Bricks. If you use other page builders, keep an eye on our series for future guides.
Should you need to display posts with additional specific criteria, you can refer to it. Hope it can be helpful to you!
- How to Show Upcoming Events - P1 - Using Meta Box and Elementor
- How to Show Upcoming Events - P2 - Using Meta Box and Bricks
- How to Show Upcoming Events - P3 - Using Meta Box and Oxygen
- How to Show Upcoming Events - P4 - Using MB Views
- How to Show Upcoming Events - P5 - Using Meta Box and Breakdance
Other series you might be interested in
- Author Bio
- Better 404 Page
- Blogs for Developers
- Building a Simple Listing Website with Filters
- Building an Event Website
- Building Forms with MB Frontend Submission
- Coding
- Create a Chronological Timeline
- Custom Fields Fundamentals
- Design Patterns
- Displaying Posts with Filters
- Download and Preview Buttons
- Dynamic Banners
- FAQs Page
- Featured Products
- Full Site Editing
- Google Fonts
- Gutenberg
- Hotel Booking
- Latest Products
- Logo Carousel
- MB Views Applications
- Meta Box Builder Applications
- Meta Box Group Applications
- Most Viewed Posts
- Opening Hours
- OTA Website
- Product Page
- Product Variations
- Querying and Showing Posts by Custom Fields
- Recipe
- Restaurant Menus
- SEO Analysis
- Simple LMS
- Speed Up Website
- Taxonomy Thumbnails
- Team Members
- User Profile
- Video Gallery