Satori ACF Field Loop
ACF Field block for WordPress Query Loop – output ACF fields inside patterns.
by Stephen Mason · github.com/ssmason/wp-gutenberg-block-acf-query-loop · 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/ssmason/wp-gutenberg-block-acf-query-loop/archive/refs/heads/main.zipACF Field block for WordPress Query Loop. Output ACF (Advanced Custom Fields) field values inside Query Loop patterns, so you can design the layout in a pattern and place field data wherever you want.
Requirements
- WordPress 6.1+
- Advanced Custom Fields (ACF) 5.x or 6.x
- PHP 8.1+
Installation
- Install the plugin (via Composer or manual copy to
wp-content/plugins/). - Activate Satori ACF Field Loop and Advanced Custom Fields.
- Run
npm ci && npm run buildin the plugin directory to build block assets.
Usage
- Add a Query Loop block and configure it (e.g. post type, number of items).
- Inside the Query Loop template, add an ACF Field block.
- In the block sidebar, select the ACF field to display from the dropdown.
- The dropdown lists fields from field groups attached to the queried post type.
- Design your pattern with headings, images, paragraphs, etc., and place ACF Field blocks where you want the data.
The block outputs the field value for the current post in the loop. Supported field types include text, textarea, number, image, link, and similar scalar/structured types.
Development
# Install dependencies
npm ci
composer install
# Build block assets
npm run build
# Lint PHP
composer phpcs
composer phpcbf
Testing (Cypress E2E)
Cypress end-to-end tests cover block settings, editor behaviour, frontend render, and the REST API.
Prerequisites
- A running WordPress site with ACF and this plugin activated
- An admin user (set
WP_USERandWP_PASSWORDincypress.env.json)
Setup (required)
- Copy
cypress.env.json.exampletocypress.env.json - Set
baseUrl,WP_USER, andWP_PASSWORDto match your WordPress site
Run tests
# Run all tests (headless)
npm run cypress:run
# Open Cypress UI (interactive)
npm run cypress:open
Test suites
| File | Coverage |
|---|---|
cypress/e2e/login.cy.js |
WordPress login reaches wp-admin |
cypress/e2e/acf-field-block-settings.cy.js |
Inspector panel, field dropdown, help text |
cypress/e2e/acf-field-block-editor.cy.js |
Block insertion, preview, Query Loop coexistence |
cypress/e2e/acf-field-block-frontend.cy.js |
Frontend block wrapper render |
cypress/e2e/acf-field-block-rest.cy.js |
REST endpoint structure |
Environment
In cypress.env.json, set:
baseUrl– Your WordPress URL (e.g.http://localhost:8080)WP_USER/WP_PASSWORD– Login credentials for an existing admin userWP_PATH– WordPress path prefix:/wpfor Bedrock,""for standard WPWP_REST_PREFIX(optional) – REST API path prefix; default is/wp-json. Override only if your site serves the REST API at a different path (e.g./wp/wp-json).
Structure
satori-acf-field-loop/
├── cypress/
│ ├── e2e/ # E2E test specs
│ │ ├── login.cy.js
│ │ ├── acf-field-block-settings.cy.js
│ │ ├── acf-field-block-editor.cy.js
│ │ ├── acf-field-block-frontend.cy.js
│ │ └── acf-field-block-rest.cy.js
│ └── support/
│ ├── commands.js
│ └── e2e.js
├── block.json # Block metadata
├── build/ # Compiled assets (index.js, style-index.css)
├── includes/
│ ├── class-assets.php
│ ├── class-autoloader.php
│ ├── class-block.php # Block registration & render
│ ├── class-plugin.php
│ └── class-rest.php # REST API for field dropdown
├── src/
│ ├── edit.js # Editor component
│ ├── index.js # Block registration
│ ├── save.js # Dynamic block (null)
│ └── style.css # Editor styles
├── satori-acf-field-loop.php
├── composer.json
├── package.json
└── phpcs.xml
REST API
The plugin registers a REST endpoint for the field dropdown:
- GET
/wp-json/satori-acf-field-loop/v1/fields?post_type={post_type}
Returns ACF fields from field groups attached to the given post type. Requires edit_posts capability.
License
GPL-2.0-or-later