Custom Post Types and Post Meta

If you are using a WordPress list page that fetches posts from the WP-API, and you want to use a custom post type, or custom plugin data, you need to write some custom code in a WordPress plugin.

The WP-API doesn't support custom post types or post meta by default. Adding them is just a few lines of code, we have a sample plugin file to help.

API Support for Custom Post Types

The sample plugin needs to be edited before it will work. To add custom post type support, uncomment line 91, and change line 98 to your post type slug.

Please view the code here.

You will need to edit this file, all of the functions are commented out by default. Please read through the code, make any changes necessary, then add it to your site as a plugin.

Custom Taxonomies

A custom taxonomy is usually associated with a custom post type. For example, if you have a custom post type called product, and you have product categories of mens and womens, those are custom taxonomies.

Custom taxonomies are not in the WP-API by default, so you need to add a few lines of code to a plugin. See line 186 of the sample plugin for example code.

Events Calendar Plugin Example

Here's a video showing how to add events from the Events Calendar plugin.

The code for the Events Calendar example integration is here.

For more information on adding custom data to lists using template hooks, see  this article.

For more information on customizing the WP-API, please see these articles:

Add CPTs to the WP-API

Post meta in the WP-API