Papi Project Adds a Page Type API to WordPress

photo credit: zenobia_joy – cc

The Pages feature, although generated dynamically in WordPress, was designed for use with static, evergreen content. Pages have always been somewhat simpler than posts, which received a major boost to flexibility when custom post types came on the scene in version 3.0.

Fredrik Forsmo, a systems developer in Stockholm, Sweden, wanted to do more with pages and decided that WordPress needs a Page Type API. He created Papi, an open source project that offers a less traditional approach to working with fields and page types.

“Papi was started because creating page types didn’t exists in a good way,” Forsmo said. “ACF and other plugins only support custom fields on different post types. This is not a good way to create page types. Additionally, the URL structure isn’t ideal with custom post types.”

Inspired by the lack of adequate solutions to address this need, Forsmo spent a year developing Papi in his spare time. The idea for the project is based on EPiServer’s Page Type Builder, which offers a more object oriented method of building pages. Papi brings this same approach to WordPress.

Essentially, it allows you to create page types using an existing post type or using custom post types. It doesn’t have an admin user interface for adding all the fields. “Papi uses classes in PHP, where one class represents one page type and in your class you add all fields you need,” Forsmo explained.

After running it in production, he discovered that it’s easy to work with when it’s necessary to add new fields. Using Papi’s “page” post type, you can create different page types with different fields on the same post type, while maintaining a clean URL structure.

Forsmo believes that this is the way pages should work in WordPress. Although I don’t know if the idea will catch on with developers, the project seems useful for those rare scenarios where custom post types aren’t a good match.

Papi isn’t on the WordPress plugin directory but can be downloaded from GitHub. It’s also available as a Composer package. Papi currently works on WordPress 3.8+ (3.9+ if on HHVM) and PHP 5.3 and above. If you want to experiment with it, Forsmo has written documentation on how to get started, how to add page type meta boxes and options, functions available to use in your page type, and how to register a page type directory.