Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/airesvsg/acf-to-rest-api
Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://github.com/airesvsg/acf-to-rest-api
acf api custom fields rest rest-api wordpress wordpress-plugin wp wp-api
Last synced: 27 days ago
JSON representation
Exposes Advanced Custom Fields Endpoints in the WordPress REST API
- Host: GitHub
- URL: https://github.com/airesvsg/acf-to-rest-api
- Owner: airesvsg
- Created: 2016-01-03T00:20:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-06-10T20:34:05.000Z (over 1 year ago)
- Last Synced: 2024-09-30T05:04:36.557Z (about 1 month ago)
- Topics: acf, api, custom, fields, rest, rest-api, wordpress, wordpress-plugin, wp, wp-api
- Language: PHP
- Homepage: https://wordpress.org/plugins/acf-to-rest-api/
- Size: 72.3 KB
- Stars: 1,325
- Watchers: 28
- Forks: 110
- Open Issues: 147
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
ACF to REST API
====
Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) Endpoints in the [WordPress REST API](https://developer.wordpress.org/rest-api/)https://wordpress.org/plugins/acf-to-rest-api/
- [Installation](#installation)
- [Endpoints](#endpoints)
- [Filters](#filters)
- [Deprecated Filters π](#deprecated-filters)
- [Request API Version π](#request-api-version)
- [Field Settings π](#field-settings)
- [Editing the Fields](#editing-the-fields)
- [Examples](#examples)
- [Get ACF Fields Recursively π](#get-acf-fields-recursively)
- [Cache](#cache)Installation
====
1. Copy the `acf-to-rest-api` folder into your `wp-content/plugins` folder
2. Activate the `ACF to REST API` plugin via the plugin admin pageEndpoints
====| Endpoint | READABLE | EDITABLE |
|----------|:--------:|:--------:|
| /wp-json/acf/v3/posts π | β | β |
| /wp-json/acf/v3/posts/**{id}** | β | β |
| /wp-json/acf/v3/posts/**{id}**/**{field-name}** | β | β |
| /wp-json/acf/v3/pages π | β | β |
| /wp-json/acf/v3/pages/**{id}** | β | β |
| /wp-json/acf/v3/pages/**{id}**/**{field-name}** | β | β |
| /wp-json/acf/v3/users π | β | β |
| /wp-json/acf/v3/users/**{id}** | β | β |
| /wp-json/acf/v3/users/**{id}**/**{field-name}** | β | β |
| /wp-json/acf/v3/**{taxonomy}** π | β | β |
| /wp-json/acf/v3/**{taxonomy}**/**{id}** π | β | β |
| /wp-json/acf/v3/**{taxonomy}**/**{id}**/**{field-name}** π | β | β |
| /wp-json/acf/v3/comments π | β | β |
| /wp-json/acf/v3/comments/**{id}** | β | β |
| /wp-json/acf/v3/comments/**{id}**/**{field-name}** | β | β |
| /wp-json/acf/v3/media π | β | β |
| /wp-json/acf/v3/media/**{id}** | β | β |
| /wp-json/acf/v3/media/**{id}**/**{field-name}** | β | β |
| /wp-json/acf/v3/**{post-type}** π | β | β |
| /wp-json/acf/v3/**{post-type}**/**{id}** π | β | β |
| /wp-json/acf/v3/**{post-type}**/**{id}**/**{field-name}** π | β | β |
| /wp-json/acf/v3/options/**{id}** π | β | β |
| /wp-json/acf/v3/options/**{id}**/**{field-name}** π | β | β |Filters
====
| Filter | Argument(s) |
|-----------|-----------|
| acf/rest_api/id | mixed ( string, integer, boolean ) **$id**
string **$type** π
string **$controller** π |
| acf/rest_api/key | string **$key**
WP_REST_Request **$request**
string **$type** |
| acf/rest_api/item_permissions/get | boolean **$permission**
WP_REST_Request **$request**
string **$type** |
| acf/rest_api/item_permissions/update | boolean **$permission**
WP_REST_Request **$request**
string **$type** |
| acf/rest_api/**{type}**/prepare_item | mixed ( array, boolean ) **$item**
WP_REST_Request **$request** |
| acf/rest_api/**{type}**/get_fields | mixed ( array, WP_REST_Request ) **$data**
mixed ( WP_REST_Request, NULL ) **$request** |
| acf/rest_api/field_settings/show_in_rest π | boolean **$show** |
| acf/rest_api/field_settings/edit_in_rest π | boolean **$edit** |Basic example of how to use the filters, in this case I will set a new permission to get the fields
```PHP
add_filter( 'acf/rest_api/item_permissions/get', function( $permission ) {
return current_user_can( 'edit_posts' );
} );
```Deprecated filters
====
| Filter | Argument(s) |
|-----------|-----------|
| acf/rest_api/type | string **$type** |
| acf/rest_api/types | array **$types** |
| acf/rest_api/default_rest_base | boolean **$default**
string **$type** |Request API version
====
See below how to select the Request API Version.1. Open the plugins page;
2. Click the settings link under the pluing name ( `ACF to REST API` );
3. Select your version in the `ACF to REST API` session;
4. Click in the button Save changes.The other alternative is to define the constant `ACF_TO_REST_API_REQUEST_VERSION` in your `wp-config.php`
```PHP
define( 'ACF_TO_REST_API_REQUEST_VERSION', 2 );
```Field Settings
====
In this version is possible to configure the field options via admin.The options are enabled using the filters below, by default theses options are disabled.
```PHP
// Enable the option show in rest
add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );// Enable the option edit in rest
add_filter( 'acf/rest_api/field_settings/edit_in_rest', '__return_true' );
```Editing the fields
====
The fields should be sent into the key `fields`.**Action:** http://localhost/wp-json/acf/v3/posts/1
```HTML
Site:
Save```
**Action:** http://localhost/wp-json/wp/v2/posts/1
```HTML
Title:
ACF
Site:
Save```
Use the filter `acf/rest_api/key` to change the key `fields`.
```PHP
add_filter( 'acf/rest_api/key', function( $key, $request, $type ) {
return 'acf_fields';
}, 10, 3 );
```Now, the fields should be sent into the key `acf_fields`
```HTML
Site:
Save```
Examples
====
Sample theme to edit the ACF Fields.https://github.com/airesvsg/acf-to-rest-api-example
To-do list π
https://github.com/airesvsg/to-do-list-acf-to-rest-api
Get ACF Fields Recursivelyπ
====
https://github.com/airesvsg/acf-to-rest-api-recursiveMore details:
- Issues
- https://github.com/airesvsg/acf-to-rest-api/issues/109
- https://github.com/airesvsg/acf-to-rest-api/issues/223
- https://github.com/airesvsg/acf-to-rest-api/issues/9- Pull Request
- https://github.com/airesvsg/acf-to-rest-api/pull/95Cache
====
Enable caching for WordPress REST API and increase speed of your application.https://github.com/airesvsg/wp-rest-api-cache