Still looking for a simple way to handle a POC to create a straightforward and simple API with a minimum of work.
I had 2 main objectives for this POC like in the previous post:
- This API should populate data for mobile application so I must be able to minimize/shrink the values exposed in the json output.
- As it is a POC, my purpose is to be totally autonomous. I do not want to rely on developers in the conception and creation of this API.
Why should I reinvent the wheel ? So why do not leverage on WordPress and especially since the version of WP 4.4, WP has a powerful API.
For those, who know already WP, I will just indicate what I will try to make the best of WP using : Post Type, Taxonomy, Custom Fields… etc.
I had in mind this time not an API to manage translations but an API to handle Urban Art Spots such as the website Urbacolors.
The WP REST API ecosystem
Here is the list of plugin that will enhance and ease your experience within the WP REST API.
I have tested them all, according to my needs, here is my feedback on each of them.
- These 3 plugins : REST API Log, WP Rest Routes, REST API Console are essential. If you want to work with the WP API, it is required.
- ACF to REST API: in my opinion, you’ll better use this plugin instead of ACF to WP API. It goes as a kind of “bundle” with the ACF (Advanced Custom Fields) Plugin for WordPress. Very powerful if you intend to use Custom Fields within your API.
- WP REST API: when you are using WP 4.4 and more, it is useless to install this plugin.
- WP REST API Cache: when you are in the development phase, it is useless to work with a cache because you can not see immediately the changes in JSON format for instance. In production, you can use it for sure.
Make you own plugin
The thing is that it is very easy to create your own plugin within WP especially if you want to use post_type. That is the best to do. It is a main purpose of my plug-in : managing 5 post_type with a custom and common taxonomy.
For some purpose, I did also some Custom Fields but believe me, better use the ACF plugin for POC at least and making Custom Fields, with the help of ACF (Advanced Custom Fields) plugin is a piece of cake.
I have made 2 “uncompleted” but sufficient plugins for the POC.
You can find on github @
Look for bf_poc_api_wp in https://github.com/bflaven/PluginWordpressForFun
- Urban Art Hunting App
- WP REST API Urban Art Hunting App
Few Web API Endpoint Reference for WP API
<!-- main Endpoint --> http://[path-to-your-worpress]/wp-json/wp/v2/ <!-- Posts Endpoint --> http://[path-to-your-worpress]/wp-json/wp/v2/posts <!-- etc... -->
If you declare for each post_type
'show_in_rest' => true,, automatically the WP API will show up your post_type.
You will get 2 routes with the same methods as you will have for the posts
For instance, our post_type is named locations
Show all the locations
wp/v2/locations ... methods": [ "GET", "POST" ],
All methods for each locations record
wp/v2/locations/(?P<id>[\\d]+) ... "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ],
Some of the routes that automatically created by WP
Part 1 : The routes of the WordPress API
Part 2 : The routes of the WordPress API
REST API plugins
This Plugin WP Rest Routes is great. It will enable you to manage the routes of your API and the data displayed for each route. It is a true vital plugin.
In my opinion, the other 2 plugins (REST API Log, REST API Console) are useful but not vital.
Plugin WP Rest Routes – Part 1
Plugin WP Rest Routes – Part 2
Plugin WP Rest Routes – Part 3 – JSON output from the route
get_locations defined in the Plugin WP Rest Routes
The input of our previous screens capture inside the admin of WP, our post_type is named
The REST API Log useful to get data on traffic and on API’s usage
The REST API Console plug-in that simply list the endpoints. Not bad
WP API has several advantages. I will stress 2 of them.
- Using WP gives the opportunity to anyone to create content that will be displayed in the API. It seems obvious but when you are working with people specialized for instance in Art, Literature or in any area. It is better to let them create the content to avoid any mistakes. Focus on the container and not on the content should be your motto.
- With the help of the Plugin WP Rest Routes, you have the ability to design the architecture quickly with all the routes of your future API. Thus, it will give you a living example for your future development with more experienced developers. According to the proverb : “A picture is worth a thousand words”.
- wp-api-menus from Fulvio Notarstefano
- Leveraging the WordPress REST API
- WP REST API Part 2: Customizing Default Endpoints and Adding New Ones
- Adding custom routes to the WordPress REST API
- WP API: Adding Custom Endpoints
- How to: create a custom endpoint with the core REST API in WordPress
- Adding fields to the JSON response + Removing fields from the JSON response
- My best practices to developing with WP-API
- Unset data from WordPress API (wp-json)
- REST API Usage Example
- Working with post meta data using the WordPress REST API
- Excellent post from Basememara – Full Stack iOS and WordPress in Swift
- Compatible Plugins & Tools from WP REST API
- Custom post types in WordPress
- Plugin Advanced Custom Fields
- Adding Custom Fields to a Custom Post Type, the Right Way
- WordPress custom post types and advanced custom fields
- Ultimate Guide to Custom Post Types in WordPress
- Unable to save custom taxonomy terms in a custom-built metabox from stackexchange
- Saving Taxonomy Terms from stackexchange
- The Custom Post Types Guide for WordPress
- WordPress Taxonomies Extra Fields the easy way
- Add a Metabox to Your Custom Post Type Screen
- WordPress Meta Boxes
- How To Create WordPress Meta Boxes
- Create custom taxonomy and Display in metabox dropdown from stackexchange
- Code add-metabox-to-taxonomy.php
- How I add a WordPress MetaBox
- My WordPress Meta box Class from bainternet
- How To Create A Better Meta Box In WordPress Post Editing Page
- WordPress Meta Boxes: a Comprehensive Developer’s Guide
- Add special meta box to custom post type from Stackexchange
- WordPress Meta Box for custom post type from stackoverflow
- Adding a custom post type with custom meta box in wordpress
- Creating Post Type Relationships
- The Practical Guide to Multiple Relationships Between Posts in WordPress
- Relationships between Post Types in WordPress
- Relation Post Types : Faire des relations entre les contenus de WordPress !
- Post relationships: Parent-to-child
- Part 9 – Many-to-many relationships in Toolset
- Many to Many Relationship between Two Custom Post Types
- One-to-many Relationships in WordPress
- Understanding and Working with Relationships Between Data in WordPress
- Create many-to-many relationships between posts of any type using post 2 post plugin
- Using 1 taxonomy for multiple post types? from stackexchange
- Add Exactly The Same Taxonomies To Multiple Custom Post Types
- Extending the Quick Edit Tool for Taxonomy Terms
- WordPress post to post relationships, without altering the Database, excellent post on one-to-many in WP
- Creating Many to Many Relationships Between Posts in WordPress
- WordPress, custom post type relationship to many post from stackoverflow
- Relating Posts, Pages, and Custom Post Types in WordPress
- How to set parent-child relationship between differents custom post types
- Extending WordPress With Custom Content Types
- How to Use Radio Buttons With Taxonomies
- WordPress: Custom post types and parent-child relationships
- Plugin Custom Post Type UI
- Plugin Posts 2 Posts
- Posts 2 Posts, un plugin pour créer des relations entre les types de contenus de WordPress
- Personnaliser l’icône d’un custom post type avec la police dashicons
- How To Design And Style Your WordPress Plugin Admin Panel
Custom Post Types, Custom Fields & Custom Taxonomy
Create a Meta Box in WP
Parent Child Relationships issue