ACF Post Object Enrichment
Adds a UI to ACF Post Object and Relationship fields to automatically attach additional ACF field values to each returned WP_Post object.
by SnippetNest · github.com/zackpyle/acf-post-object-enrichment · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/zackpyle/acf-post-object-enrichment/archive/refs/heads/main.zipReadme
ACF Post Object Enrichment
Automatically attach additional ACF field values to every WP_Post object returned by an ACF Post Object or Relationship field — no extra get_field() calls needed in your templates.
How it works
The plugin adds an "Attach additional fields" setting to the ACF field editor for Post Object and Relationship fields. Select which ACF fields you want pre-loaded, and those values will be available as properties directly on every WP_Post object the field returns.
// Without this plugin
$posts = get_field( 'featured_articles' );
foreach ( $posts as $post ) {
$hero = get_field( 'hero_image', $post->ID );
$date = get_field( 'publish_date', $post->ID );
}
// With this plugin (after selecting hero_image + publish_date in the field settings)
$posts = get_field( 'featured_articles' );
foreach ( $posts as $post ) {
$hero = $post->hero_image;
$date = $post->publish_date;
}
Requirements
- WordPress 5.9+
- PHP 8.1+
- Advanced Custom Fields (free or Pro)
Installation
- Download or clone this repository into your
wp-content/plugins/directory. - Activate ACF Post Object Enrichment from the WordPress Plugins screen.
Auto-updates are delivered via GitHub — the plugin will appear in your WordPress updates dashboard whenever a new release is published.
Usage
- Open any ACF field group and edit a Post Object or Relationship field.
- Scroll to the "Attach additional fields" setting.
- Click + Add field and select the fields you want attached. The picker shows all ACF fields registered for the post types the field targets.
- Save the field group.
From this point on, get_field() (or the_field()) for that field will return WP_Post objects with the selected fields already populated as properties.
Note: The enrichment setting is hidden when the Post Object field's Return Format is set to Post ID, since enrichment only applies to object returns.
Example Use Case
Say you have a Books post type and a Post Object field called featured_books that lets editors pick a handful of books to highlight. Each book post has two custom fields: book_author (text) and book_genre (text).
In the ACF field group editor, find the featured_books field and use the Attach additional fields setting to add book_author and book_genre — just click + Add field for each one.
Now in your template, each book post object already has book_author and book_genre ready to go:
$books = get_field( 'featured_books' );
foreach ( $books as $book ) {
echo $book->book_author;
echo $book->book_genre;
}
No nested get_field() calls needed.
Notes
- Values are resolved using
get_field(), so they respect ACF's formatting — images return arrays, relationships return arrays ofWP_Postobjects, etc. - The picker auto-detects which post types the field targets and scopes the field list accordingly. It falls back to all available ACF fields when no post type filter is set.
- Field names are stored as a comma-separated string internally.
License
GPL-2.0-or-later — see LICENSE.
Author
Built by SnippetNest. Plugin detail page: snippetnest.com/snippet/extend-acf-post-object-relationship-fields-custom-data.
Read the full README on GitHub →
Releases
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.