Visual field groups
Drag fields into place, set labels, defaults and instructions, and group them with tabs and accordions.
Wonder Fields lets you add structured content to posts, pages, users, terms, menus, options pages and blocks. Build field groups visually, then show the values in your theme with one line of PHP.
get_field() APIsection_titleTextintroWYSIWYGteamRepeaternameTextphotoImageDesign the editing experience your clients see, and keep full control of how data is stored and displayed.
Drag fields into place, set labels, defaults and instructions, and group them with tabs and accordions.
Show a group only where it belongs with AND / OR rules, and hide fields based on other answers with conditional logic.
Let editors add rows or pick from layouts to build sections like team lists, FAQs and page builders of your own.
Register Gutenberg blocks with wf_register_block_type() and render them from a plain PHP template.
Create custom post types, taxonomies and site-wide options pages from the admin, with no extra plugin.
Keep field settings in version control as JSON, and read or update values through the WordPress REST API.
wf_ functionsGoogle MapsFront-end formsPick a category to see what each field stores. The code name in grey is the value you choose for type when registering fields in PHP.
A repeater holds any number of rows of sub fields. Flexible content goes further: editors choose a layout for each row, and your template decides how each one looks.
have_rows() and the_row()get_row_layout()add_row() and update_row()Register a block, attach a field group to it, and render it from a template file. Editors fill in fields in the sidebar and see a live preview in the editor.
wf/your-block automatically$block, $is_preview and $post_idget_field() inside the template as usual“We rebuilt our whole site structure in an afternoon.”
Every time you save a field group, post type, taxonomy or options page, Wonder Fields writes a JSON file to your theme. Deploy it to another site and sync it with one click.
wonder-fields-json/ in the active themesave_json and load_json filtersUpload the plugin zip from Plugins › Add New › Upload Plugin and activate it. A Wonder Fields menu appears in the admin.
Add fields, choose where the group shows with location rules, and publish. Editors see the fields on their edit screens right away.
Print values with the_field(), loop repeaters with have_rows(), or connect fields in your page builder.
Start at the top if you are new. Each section is short and includes code you can copy into your theme.
Wonder Fields needs WordPress 6.0 or newer and PHP 7.4 or newer.
wonder-fields.zip and click Install Now. You can also upload the wonder-fields folder to /wp-content/plugins/ by FTP.wonder_fields/settings/google_api_key filter.A field group is a set of fields that appears together on an edit screen. Here is how to add a subtitle and hero image to every page.
subtitle). Choose the field type.hero_image with the Image type.hero_image.Location rules decide which edit screens show a group. Rules in the same row must all match (AND). Add a rule group to show the fields when either set matches (OR).
| Area | Rules you can use |
|---|---|
| Posts | Post Type, Post Template, Post Status, Post Format, Post Category, Post Taxonomy, Post |
| Pages | Page Template, Page Type (front page, posts page, top level, parent, child), Page Parent, Page |
| Users | Current User, Current User Role, User Form, User Role |
| Other screens | Taxonomy, Attachment, Comment, Widget, Menu Item, Block, Options Page |
Conditional logic keeps edit screens tidy. Open a field, turn on Conditional Logic, and pick the field and value it depends on.
For example, add a True / False field called has_video, then give an oEmbed field the rule has_video is checked. The video field only appears once the box is ticked. Hidden fields are skipped when the post is validated and saved.
Use the_field() to print a value and get_field() to get it for use in your own markup. Both read from the current post unless you pass a post ID.
<h2><?php the_field( 'subtitle' ); ?></h2>
<?php
$image = get_field( 'hero_image' );
if ( $image ) {
echo wp_get_attachment_image( $image['ID'], 'large' );
}
// Read from another post.
$price = get_field( 'price', 42 );
?>All 21 functions: get_field, the_field, get_fields, get_field_object, get_field_objects, update_field, delete_field, have_rows, the_row, get_row, get_row_layout, get_row_index, reset_rows, get_sub_field, the_sub_field, get_sub_field_object, update_sub_field, delete_sub_field, add_row, update_row, delete_row.
wf_ version, such as wf_get_field(). It is always available, even if another plugin already defines the unprefixed name.Create a Repeater field called team with sub fields name and role. Then loop the rows in your template:
<?php if ( have_rows( 'team' ) ) : ?>
<ul class="team">
<?php while ( have_rows( 'team' ) ) : the_row(); ?>
<li>
<h3><?php the_sub_field( 'name' ); ?></h3>
<p><?php the_sub_field( 'role' ); ?></p>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>A Flexible Content field holds rows that each use one of several layouts. Check the layout name for each row and output the right markup.
<?php while ( have_rows( 'sections' ) ) : the_row();
if ( 'hero' === get_row_layout() ) {
get_template_part( 'sections/hero' );
} elseif ( 'gallery' === get_row_layout() ) {
get_template_part( 'sections/gallery' );
}
endwhile; ?>Pass a second argument to say where the value is stored.
| Where | Pass as post ID | Example |
|---|---|---|
| A post or page | The ID or a WP_Post | get_field( 'price', 42 ) |
| Options page | option or options | get_field( 'phone', 'option' ) |
| User | user_{ID} or WP_User | get_field( 'bio', 'user_7' ) |
| Term | term_{ID} or {taxonomy}_{ID} | get_field( 'color', 'category_3' ) |
| Comment | comment_{ID} | get_field( 'rating', 'comment_12' ) |
| Widget | widget_{ID} | get_field( 'title', 'widget_text-2' ) |
Options pages hold values that apply to the whole site, like a phone number or social links. Create one under Wonder Fields›Options Pages, or in code:
wf_add_options_page( array(
'page_title' => 'Site Settings',
'menu_slug' => 'site-settings',
) );Then set a field group's location to Options Page is equal to Site Settings, and read values with get_field( 'phone', 'option' ).
Register the block in functions.php, create a field group with the location Block is equal to Testimonial, and write the template.
add_action( 'init', function () {
wf_register_block_type( array(
'name' => 'testimonial',
'title' => 'Testimonial',
'icon' => 'format-quote',
'render_template' => 'template-parts/blocks/testimonial.php',
) );
} );<blockquote class="testimonial">
<p><?php the_field( 'quote' ); ?></p>
<cite><?php the_field( 'author' ); ?></cite>
</blockquote>The block is registered as wf/testimonial. Templates also receive $block, $content, $is_preview and $post_id.
Groups registered in PHP load fast and can't be changed by accident in the admin. Tip: build a group in the admin first, then use Tools›Generate PHP to get this code for you.
add_action( 'wonder_fields/include_fields', function () {
wf_add_local_field_group( array(
'key' => 'group_hero',
'title' => 'Hero',
'fields' => array(
array(
'key' => 'field_hero_title',
'name' => 'hero_title',
'label' => 'Title',
'type' => 'text',
),
),
'location' => array(
array(
array( 'param' => 'post_type', 'operator' => '==', 'value' => 'page' ),
),
),
) );
} );wonder-fields-json folder in your active theme. Field groups, post types, taxonomies and options pages are saved there as JSON whenever you save them.// Save JSON to a custom folder.
add_filter( 'wonder_fields/settings/save_json', function () {
return get_stylesheet_directory() . '/fields';
} );Turn on Show in REST API in a field group's settings. Its values then appear in a wonder_fields property on /wp/v2 responses, and you can update them by sending the same property back.
{
"id": 42,
"title": { "rendered": "About" },
"wonder_fields": {
"subtitle": "Meet the people behind it",
"hero_image": 318
}
}Most filters also accept /type=, /name= and /key= variants, so you can target one field type, one field name or one field key.
| Hook | Use it to |
|---|---|
wonder_fields/save_post | Run code after values are saved. Use a priority below 10 to run before. |
wonder_fields/load_value | Change a value as it is loaded from the database. |
wonder_fields/update_value | Change a value before it is saved. |
wonder_fields/format_value | Change the value your template receives. |
wonder_fields/validate_value | Add your own validation errors. |
wonder_fields/prepare_field | Change or hide a field just before it is shown. |
wonder_fields/load_field | Change field settings when they load. |
// Require a subtitle of at least 10 characters.
add_filter( 'wonder_fields/validate_value/name=subtitle', function ( $valid, $value ) {
if ( strlen( $value ) < 10 ) {
return 'Please write at least 10 characters.';
}
return $valid;
}, 10, 2 );Connect fields to text, images and links without writing a template.
Dynamic tags in a "Wonder Fields" group for text, URL, image, gallery, number and color.
Use {wf_fieldname}, or {wf_fieldname:option} for options pages.
Pick fields from "Wonder Fields" field connections.
Fields are listed under Dynamic Content in any module.
Find fields under Dynamic Data › Wonder Fields.
[wonder_field name="subtitle"] with optional post_id. Add format="0" for the raw value.
Yes. Wonder Fields is released under the GPLv2 or later license, with every field type and feature included.
Wonder Fields uses the same function names, such as get_field(), have_rows() and the_sub_field(). If another plugin already defines those names, use the wf_ versions like wf_get_field(), which are always available.
Yes. Field groups appear in both, and you can build your own Gutenberg blocks with wf_register_block_type().
In the standard WordPress meta tables for posts, users, terms and comments, and in options for options pages. Your content stays in your database.
Use Local JSON and commit the wonder-fields-json folder with your theme, or export a JSON file from Wonder Fields › Tools and import it on the other site.
No. The shortcode and page builder integrations never output password fields.
WordPress 6.0 or newer and PHP 7.4 or newer. The Google Map field also needs a Google Maps JavaScript API key.
Install Wonder Fields, build your first field group and see it on the page in minutes.