How to create custom endpoints for ACF Pro custom fields

In this post we will learn a bit about the compatibility work that we’ve done recently with ACF and ACF Pro (single and repeating fields)

By Adriano Ferreira

Rest Routes and ACF custom fields

 

We’ve been busy these weeks working in a major feature for Rest Routes. After noticing that many of our clients are actively using ACF and ACF Pro for building custom fields, we’ve decided to integrate it with our Pro plugin. Now, you can easily expose ACF custom fields through your custom endpoints built with Rest Routes Pro.

You will be able to display any kind of ACF custom field, not only single but also repeating ones. We really hope that you enjoy this feature as much as we did while developing that.

Preparation

 
First all, you will need to have ACF and ACF Pro installed and also a few custom fields defined for Posts. You can create as many custom fields as you want, single and repeating ones.

 

Adding the Custom Endpoint 

 

Let’s first create our new Route:

 

 

We are going to have only one endpoint for this route. So, let’s select the GET method as well as the purpose of the endpoint (Display Posts).

 

 

Now, it is time to define the output of the endpoint. For this, let’s select three fields: post_title, locations (custom field) and state_resources (custom field). At this stage it is very important that you pay attention to the custom field names, it must be exactly like the ones you defined once creating those on ACF.

 

 
Ok, at this point everything is ready. Let’s now navigate to the endpoint URL and check if the custom fields are correctly displayed there: wp-json/acme/v1/acf
 


Awesome! All the fields and sub fields defined on ACF are properly displayed!

Conclusion

 

This was just a basic tutorial showing you how easy is to create custom REST API endpoints for your WordPress sites and add some custom fields from ACF Pro. There are many other features and possibilities you can do through the plugin and many new features are coming up soon.

Does this plugin sounds like a good fit for your site? Click here and start building awesome routes for your site now.

Join our 322,204 newsletter subscribers and get the latest news and articles sent straight to your inbox weekly


Rest Routes 4.0

Rest Routes 4.0 is out! Today is the day that we will be bringing to you some of the most asked features ever. Please take

Read More »

Rest Routes 3.6.0

Rest Routes 3.6.0 We’ve introduced a very interesting feature on this release. Now you will be able to create custom endpoints for editing posts, taxonomies

Read More »

WordPress Plugin Skeleton

WordPress Plugin Skeleton A simple starting point for developing WordPress plugins By Adriano Ferreira Starting a new plugin can be a hassle! Many default files

Read More »