O'Reilly logo

WordPress Plugin Development Cookbook by Yannick Lefebvre

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying custom post type data in shortcodes

While displaying a list of custom post type items can be done using the archive page as shown in the previous recipe, it might be desirable to display a list of these elements in other places such as a page or post, or perhaps even on the front page as part of the basic template. In any of these cases, a good solution to display these items is to create a shortcode that will display one or more posts in any of these site areas.

This recipe shows how to create a shortcode that will retrieve and display five Book Reviews at a time, with accompanying navigation links.

Getting ready

You should have already followed the Creating an archive page for custom post types recipe to have a starting point for this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required