add_action( 'rest_api_init', function() { register_rest_route( 'myplugin/v1', '/options/', array( 'methods' => 'GET, PUT', 'callback' => 'my_options_handler' ) ); } );
function my_options_handler( $data ) {
$name = $data['name'];
// Use an "options" field group ID for options pages $options_id = 'options';
// Use the field name as the key in the returned array $options = get_field( $name, $options_id );
// Return the options as an array return array( $name => $options );
}
https://example.com/wp-json/myplugin/v1/options/?name=my_option_name
其中,myplugin/v1是注册的路由,options是路由名称,my_option_name是ACF选项名称。
以上是解决ACF Pro选项REST API路由不起作用的方法。