Custom fields, post types and taxonomies
Last updated
Custom fields store extra information on a post, page or user, beyond the title and content. A property listing might have a price, a number of bedrooms and a photo gallery. A post type is a new kind of content, such as Properties or Events, and a taxonomy is a way of grouping it, such as Locations or Genres.
The Custom fields module does what Advanced Custom Fields (ACF) and Custom Post Type UI do, and stores values the same way ACF does. That means a theme built for ACF can keep working, and switching the module off never deletes your values.
Switching Custom fields on
Open the site page in MaintainHQ and choose Content, then Custom fields. Press "Install and switch on Custom fields" (or "Switch on Custom fields").
In MaintainHQ the screen has four tabs: Field groups, Post types and taxonomies, Import and export, and Settings. In WordPress, Custom fields has its own menu item with tabs for Field groups, Post types, Taxonomies, Options pages, and Import and export.
Field groups
A field group is a set of fields shown together, with location rules that decide where it appears: on a post type, a page template, a taxonomy, a user or role, or an options page (a settings screen of its own in wp-admin).
You add and edit fields in WordPress. In MaintainHQ, press "Add field group in WordPress" to open the editor, or the open link on a group to edit it.
There are 22 field types: text, text area, number, email, URL, select, checkboxes, radio buttons, true or false, date, colour, image, file, gallery, link, post, relationship, taxonomy terms, user, rich text, repeater and group.
In MaintainHQ, the Field groups tab lists each group with its fields and where it is shown. Groups can be marked From ACF, Imported, Copied, In code (defined in the theme, so they cannot be switched or deleted here) or REST (available to the REST API). From the list you can:
- Switch a group on or off.
- Download it as JSON.
- Copy it to another site you manage (see below).
- Delete it. Values already saved on your content are kept.
Post types and taxonomies
On the "Post types and taxonomies" tab, under "Add a post type or taxonomy":
- Choose Post type or Taxonomy.
- Enter a Name (a short lowercase id such as product or genre).
- For a post type, list the taxonomies it uses; for a taxonomy, list the post types it belongs to (comma separated).
- Enter a Singular label and a Plural label, for example Product and Products.
- Choose whether it is hierarchical: like pages (with parents and children) for post types, or like categories for taxonomies.
- Press "Add post type" or "Add taxonomy".
Each one can be switched on or off, or deleted. Deleting keeps the content already saved, but it will not show until it is registered again. Options pages are added in WordPress, where you choose whether they get their own menu item or sit under Settings, Appearance or Tools.
Showing field values on the site
There are several ways to show a value, depending on how the site is built:
- The shortcode [mhqst_field name="price"] in posts and pages. It can be switched on or off in Settings.
- Block bindings (WordPress 6.5 or later), which connect a block to a field.
- Template functions for theme developers, such as mhqst_field() and mhqst_the_field(), plus a row loop for repeaters.
- A read-only REST API property, switched on per field group.
The shortcode and block bindings read only fields defined in a group, only from content a visitor is allowed to read, and never user fields, so they cannot leak private information.
Copying, importing and exporting
To reuse a field group on another site, press the copy button on the group, choose a site under "Copy to", and decide whether to "Switch it on there straight away" and whether to "Replace a group with the same key on that site". The group and its fields are copied; values saved on this site stay here. Custom fields must be switched on at the other site first.
The Import and export tab offers:
- Download JSON or Download PHP: every field group, post type, taxonomy and options page on the site. PHP is for pasting into a theme.
- Import JSON: a file exported from Custom fields, or ACF’s own JSON export. Items already on the site are skipped unless you tick "Replace items already on this site".
- Import from ACF: brings over ACF field groups, post types and taxonomies with their keys and names.
Moving from ACF
Because values are stored in ACF’s layout, the values ACF saved can be read straight away after an import. The safest way to move is:
- Switch Custom fields on.
- Use the "Import and switch off" offer at the top of the screen. Everything imported from ACF arrives switched off, so nothing shows twice while ACF is still running.
- When MaintainHQ switches ACF off, everything imported from ACF that is still off is switched on, together with the ACF functions your theme uses (get_field, the_field, have_rows and the rest).
- Check the site. If something is wrong, press "Switch ACF back on", which reverses exactly those changes.
The setting "ACF functions for themes written for ACF" provides those functions only while ACF is not active, so the two never clash.
Switching off safely
"Switch Custom fields off" keeps every value. Removing the data, after typing REMOVE, deletes every field group, post type and taxonomy defined in the module. Even then, values saved on posts, terms and users stay in the database, because they belong to WordPress.