Home › Forums › General Issues › How can I retrieve fields from an options page using the REST API (v5.11)? › Reply To: How can I retrieve fields from an options page using the REST API (v5.11)?
Thanks to your suggestion I wound up learning how to create a custom endpoint, so thanks for that!
I wound up creating a custom endpoint that executes and returns the result of a get_field();
call against my options field, which worked a charm.
Here’s what I wound up with, in case it’s helpful for anyone else trying to do something similar:
Set up the endpoint and callback:
function cp_colspec_endpoint() {
$field = get_field('col_spec','options');
return $field;
}
//expose acf options page field(s) through custom endpoint
function cp_register_api_endpoints() {
register_rest_route( 'canopy/v2', '/acf--colspec', array(
'methods' => 'GET',
'callback' => 'cp_colspec_endpoint',
) );
}
add_action( 'rest_api_init', 'cp_register_api_endpoints' );
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.