Home › Forums › ACF PRO › 502 Bad Gateway with ACF PRO – WP REST API › Reply To: 502 Bad Gateway with ACF PRO – WP REST API
For anyone who is interested I found a solution. I extract this code into a Controller class that extends WP_REST_Controller
I then set up three methods inside of that controller; register_routes
, get_fields
and handle
. Inside of the register_routes method I simply set up the following;
register_rest_route( getenv('API_BASE') . '/v' . getenv('API_VERSION'), 'post', array(
'methods' => 'GET',
'callback' => array($this, 'handle'),
));
Inside the get_fields method I set up a simple handle to get the field by passing in a specific block;
public function get_fields($block) {
acf_setup_meta( $block['attrs']['data'], $block['attrs']['id'], true );
return get_fields();
acf_reset_meta( $block['attrs']['id'] );
}
From there the rest of the code stayed pretty much the same inside of the handle method I just changed $blocks[$key]['data'] = $fields;
to $blocks[$key]['data'] = $this->get_fields($block);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.