Search code examples
wordpressadvanced-custom-fieldswordpress-rest-api

WordPress acf-to-rest-api && Rest API


Activating ACF to REST API , breaks WP REST API

If I activate WP REST API, I can retrieve data: ( currently both enabled on the site, so links will show error)

http://ecommerce-ux.london/wp-json/wp/v2/posts?slug=hello-world

http://ecommerce-ux.london/wp-json/wp/v2/posts/1

Current error responce is

<br />
<b>Fatal error</b>:  Using $this when not in object context in <b>/home/commercect/public_html/wp-content/plugins/acf-to-rest-api-master/v3/lib/endpoints/class-acf-to-rest-api-controller.php</b> on line <b>54</b><br />

Above links don't work but if I do: http://ecommerce-ux.london/wp-json/wp/v2 it give me api calls.

As I needed to retrieve custom fields for my single post page, I've setup ACF to Rest API but that breaks my endpoints for wp/2 plugin and I can't retrieve data anymore but ACF does work:

http://ecommerce-ux.london/wp-json/acf/v3/posts/1

Responce is

{"acf":{"":false,"anchor":[{"anchor_name":"Heading","anchor_link":"heading-name"}]}}

Plugins

WP REST API SON-based REST API for WordPress Version 2.0-beta15 | By WP REST API Team http://v2.wp-api.org/

ACF to REST API Version 3.0.1-beta | By Aires Gonçalves | https://github.com/airesvsg/acf-to-rest-api

Does anyone know the work around?

enter image description here


Solution

  • After finding an example here; http://airesgoncalves.com.br/acf-to-rest-api/wp-json/acf/v2/post/1

    Got it sorted! Don't use the plugin from github. Use the one from WP.org page. https://wordpress.org/plugins/acf-to-rest-api/