Display meta value in output

Display Posts includes many display parameters for customizing what is displayed in the post listing output. You can include things like the post title, image, excerpt, content, date, author, categories, and more.

You can use the output filter to both modify existing pieces of the output (ex: default image) and add your own custom pieces to the output (ex: author avatar).

What is Metadata

Metadata is additional information about a post. Plugins use metadata to extend the functionality of WordPress. An events calendar plugin would store the event date as metadata. You can also create your own metaboxes.

Display metadata in Display Posts

The first step is to identify the meta key used for your metadata. If you’re trying to display metadata from a plugin, ask the plugin author for guidance.

Let’s use BE Events Calendar as an example. It stores the event start date with a key of be_event_start.

We’re going to add a new parameter to our shortcode, include_event_date="true", for including the event date in post listings.

Notes:

  • On line 11, change be_event_start to whatever key you’d like.
  • On line 19, I’m converting the UNIX timestamp (stored by BE Events Calendar) into a formatted date, like July 4, 2019.
  • On line 22, I’m wrapping it in <span class="event-date"> so we can style it with CSS.
  • On line 25, I’m inserting our $event_date into the output where I’d like it to appear (after the $title and before the $date). You can move it to appear wherever you’d like.

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.