Categories
WordPress

How To Access PODS Custom Post Types Using The WP Rest API

Recently I have been working with the WordPress Rest API to use WordPress as a data source. One of the issues that I ran into is when trying to access custom post types created with pods. When trying to access the end point for the custom post type I received the following error:
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}

A quick read of the WP Rest API docs will reveal that Custom Post Types don’t have routes by default. But no worries support for WP Rest API can be added to any custom post type.

To add support for the WP Rest API to a custom post type created with PODS you need to log into your WP admin area. From the menu you select Pods Admin > Edit Pods. Edit Pods
Hover over the custom post type you want to access and then choose edit. At this point you need to decide if you want to allow access to the entire custom post type or just specific fields.

Allow access to specific fields

Click to edit the field you want to access using the WP Rest API. On the PODS Field Rest API tab you can choose to allow read access, write access, or both. PODS field Rest Access

Allow access to entire custom post type

On the PODS Rest API tab you can enable Rest API Support for the custom post type. You can check the Show All Fields to or follow the steps above to just allow read access of certain fields. You can also allow all fields to be updated using the Rest API or set the write settings individually for each field.Pods CPT Rest API Support

Access PODS Custom Post Type With WP Rest API

Now you should be able to access the custom post type using something like
https://yourdomain.com/wp-json/wp/v2/quote/
Be mindful that you must change https://yourdomain.com to the site you have the custom post type on. And change quote to the REST Base for your custom post type.

 

 

Subscribe To Updates and Tips Via Email

Get tips on web development, WordPress, web design & more