Developer API overview
3 min read
Mass Custom Fields stores each field group in its own database table (see Field groups). Everything on this page is how your code gets values in and out of those tables. All of it is in the free plugin.
You want to | Use | Page |
|---|---|---|
Read a value in a template |
| |
Print a value safely |
| |
Save or clear a value from code |
| |
Point at a user, term, comment or options page |
| |
Print a value in content |
| |
Show a value in the block editor | WPM Field block, WPM Fields Block Bindings source | |
Filter or sort posts by field value |
| |
Read or write values over HTTP | the | |
Use site-wide Global Data |
| |
Verify or read a Password field |
| |
Look up an exact signature | ||
Fix something that does not work |
The two keys
Almost every function takes a group key and a field key: the Key of the field group and the Key of the field, exactly as shown in WPM Fields › Field Groups. Both are lower-case letters, digits and underscores. The functions run sanitize_key() on them, so 'Listing' and 'listing' are the same key.
$price = wpmcf_get_field( 'listing', 'price' ); // group "listing", field "price"Only top-level fields have a database column. To reach a value inside a Group or Repeater field, read the container and pass a path (see Reading values).
The object
Most functions take an optional third argument, the object the value belongs to:
wpmcf_get_field( 'listing', 'price' ); // the current post (inside the loop)
wpmcf_get_field( 'listing', 'price', 42 ); // post 42
wpmcf_get_field( 'profile', 'bio', 'user_3' ); // user 3
wpmcf_get_field( 'brand', 'color', 'term_5' ); // term 5
wpmcf_get_field( 'company', 'phone', 'option' ); // the options-page rowSee Object references for every accepted form.
The $args array
The last argument is an array of options. The ones that matter most:
Key | Used by | Meaning |
|---|---|---|
| get / has / the | Value to use when the field has no value |
| get / has / the | Reach into a Group or Repeater value |
| any function that takes an object |
|
|
|
|
|
|
|
Raw versus escaped: the one rule
Function family | Returns or prints | Escaped? |
|---|---|---|
| returns the raw value | No. You must escape it for where you print it. |
| prints formatted HTML | Yes. Safe to echo as is. |
| print formatted HTML | Yes. |
// Raw value: escape it yourself.
echo '<a href="' . esc_url( wpmcf_get_field( 'listing', 'website' ) ) . '">Website</a>';
// Printing function: already escaped.
wpmcf_the_field( 'listing', 'title' );Fault tolerance
The template functions never throw. If the plugin is not booted yet, the object is invalid, or reading fails, they return the default you passed (or null / false) and the error is logged in WPM Fields › Settings › Health. A broken field cannot break the page. When WP_DEBUG is on, a bad object argument also raises a _doing_it_wrong() notice.
Where things are not covered here
- The
{{ }}expression language, thewpmcf/...filters and actions: Variables and hooks. - Registering field groups from PHP, the post-meta bridge and GraphQL: Field groups and Integrations.
- Elementor, Bricks, Divi, Breakdance and Oxygen dynamic tags: Integrations.
- What each field type returns and prints: Field types.
The plugin's own REST namespace
wpmcf/v1 exists for the plugin's admin screens. It is not a public API: nearly every route requires the manage_options capability (see REST API). To read or write values over HTTP, use the wpmcf attribute on the core post endpoints instead.
Still stuck? Contact support