Allows you to create relationships to posts from WP Rest API Endpoints.
This ACF field type is compatible with:
- ACF 5
When editing an object with the field:
- Copy the
acf-api-fields
folder into yourwp-content/plugins
folder - Activate Advanced Custom Fields: API Fields plugin via the plugins admin page
- Create a new field via ACF and select the API Relationship type
- Enter in the endpoint to the remote API. Example http://example.com/wp-json/v2/wp/posts
- Edit the object where you have included the field group. You'll see a standard Relationship field, however the data will be populated from the remote API.
The field type returns objects from get_field(). Example template file use:
<?php $remote_posts = get_field( 'remote_post_object' ); ?>
<?php if ( !empty( $remote_posts ) ): ?>
<?php foreach ( $remote_posts as $remote_post ): ?>
<h2><?php echo esc_html( $remote_post->get_title() ); ?></h2>
<p><?php echo $remote_post->content->rendered; ?></p>
<?php endforeach; ?>
<?php endif; ?>
The object which is returned from the API is similar to the object from the Example Client Library