WordPress is not just a blogging platform anymore, but can be used to develop complex web applications for many purposes. WordPress provides variety of APIs, thus allowing us to develop further on its base.
We can extend WordPress to meet our needs using the Plugins API. With this powerful API we can develop solutions meeting our needs for near endless scenarios; therefore, to become a master of WordPress, once has to master its APIs.
In this series, we will look at the WordPress Plugins API as well as Widget API and how we can use them to develop solutions specific to our needs.
What We’re Making
During the course of this three-part series, we will build a WordPress plugin from the ground up. This plugin will display a list of upcoming events on the front-end to let users know what’s coming next. The admin will be able to publish information about new events, and will be able to edit or delete them.
There is a saying:
Failing to plan is planning to fail.
We will plan out every detail and aspect of our plugin before we begin writing code. This way, we are going to clarify what we are going to do and how we’re going to do it. We will also make sure that we have all of the necessary assets we will be using later before we begin writing our code.
We will begin by registering a custom post type for our events. This will make it easier for us to manage things efficiently. That custom post type will include:
- a title field
- a description field
- field for featured image
In addition to these standard fields, we will also include three custom meta fields for:
- event start date
- event end date
- event venue
For the event start date and event end date, we will incorporate jQuery UI date picker in our post dashboard.
The above three custom fields will save their values in post meta and we will be querying our events on the front-end on the basis of these custom fields using the meta query.
When it comes to custom post types, WordPress only shows columns for the title, author and publish date of the post on post-edit screen, but we are not limited to that. We will add custom columns for event start date, end date and the event venue for better accessibility of the user.
Finally, regarding the front-end, it’s suitable to make a widget that displays a list of all events that are scheduled in the near future. With the powerful Widget API, we will code our custom widget that we will be able to add in our sidebar or footer area.
Creating an Upcoming Events Plugin in WordPress: Custom Post Type and the Dashboard
Creating an Upcoming Events Plugin in WordPress: Creating the Widget