How to Use UiChemy Custom Fields in Code: Functions, Hooks, and REST API
A practical developer guide with everything you need to work with UiChemy Custom Fields in PHP: read and save values, query posts, loop repeaters, and extend with hooks and the REST API.
Building a theme or plugin on top of UiChemy Custom Fields? Find the task you need below, copy the code, and change the field name. Every function, hook, and route is listed at the end in the Function Index.
| Item | Value |
|---|---|
| Version | UiChemy 5.3.0, UiChemy Pro 5.3.0 |
| Requires | PHP 7.4+, WordPress 6.9+ |
| Functions | Start with uich_ |
| Classes | Start with Uich_Fields_ |
| REST namespace | uichemy-fields/v1 |
Before You Start
Get Field Values
Use Each Field Type
Query Posts by Field Value
Values are saved as normal WordPress meta, so WP_Query, get_terms(), and get_users() can filter and sort by them. Build the meta key with uich_build_meta_key(), never by hand.
Repeater Fields (Pro)
On the free plan a repeater reads null and loops return no rows.
Save and Delete Values
Change How Values Load
Create and Read Definitions
Location Rules in Code
Groups of conditions: every condition in a group must match, any one group is enough.
'location_rules' => array(
array( // group 1
array( 'param' => 'post_type', 'operator' => '==', 'value' => 'book' ),
),
array( // or group 2
array( 'param' => 'post_type', 'operator' => '==', 'value' => 'page' ),
),
),
Field Type Reference
Hooks
REST API
Namespace uichemy-fields/v1. Every route needs manage_options. Cookie requests need the wp_rest nonce.
Migrate in Code
Imports definitions and values from ACF / SCF, Meta Box, Pods, and JetEngine.
Abilities and MCP
43 abilities (19 read, 24 write) let AI tools work with Custom Fields. Names start with uichemy/ and every write accepts dry_run.
Composer Integration
Function Index
Every function in the module, by task.
Free vs Pro for Developers
| Feature | Free | Pro |
|---|---|---|
| Field types | 22 (plus legacy Password) | Adds Relationship and Repeater |
| Location rule types | 5 | 16 more |
| Conditional logic | No | Yes |
| Field binding in the page builder | No | Custom Field dynamic tags |
On the Free Plan
- Saving a group with a new Pro type, rule, or condition fails with HTTP 403.
- For Pro types,
uich_field_value()returnsnullanduich_save_field_value()returnsfalse. uich_field_values(),uich_field_values_raw(),uich_field_definitions(), anduich_get_all_field_data()aren't locked.- Downgrade-safe: Pro items already saved stay. Only new ones are refused.
How Pro Is Detected
uich_fields_is_pro(), which callsuichemy_is_pro().- The UiChemy Pro plugin (
uichemy-pro) addsUich_Pro_Fields_LocationandUich_Pro_Fields_Conditional. - Turning Pro on with the constant or
uich_composer_is_profilter without the Pro plugin leaves Conditional logic ignored and Pro rules matching nothing.
Security
Saving and Output
- Always save through
uich_save_field_value(). It checks permission and cleans the value for its type. - Escape on output.
uich_print_field()anduich_print_repeater_value()escape.uich_field_value()doesn't. - WYSIWYG runs shortcodes for every visitor, the same trust level as post content.
- The User field's default format includes email. Don't print it publicly.
Permissions
| Action | Needs |
|---|---|
| REST, import, storage routes, and definition saves | manage_options |
| Dashboard value saves | Edit permission on the object plus a nonce |
| Abilities | manage_options plus a check per object |
Exposure
- Protect the definitions folder on Nginx or IIS.
wp-content/uichemy-fields/is only protected by.htaccesson Apache. Add a rule that denies it, or the JSON files can be downloaded. - Leave Show in REST off unless you need it. The REST path uses simpler cleaning.
What Isn't Available
- No actions when a value loads, saves, or renders. Use the value filters.
- No
sanitize_valueorescape_valuefilters, and no filters for field HTML, wrappers, classes, or labels. - No JavaScript API.
- No custom field types.
- No Gallery, Flexible Content, or Clone types.
- No options page in the dashboard.
- No shortcode for field values.
- No import or export routes for definitions. Copy the files.
- No per-field or per-group permissions.
Good to Know
- Saving an unchanged number or True / False returns
false. - Backslashes are removed from post, term, user, and comment values, including saves through
uich_save_field_value(), not only the dashboard. Options keep them. - The "get all" functions skip the load filters.
uich_field_values(),uich_field_values_raw(),uich_field_definitions(), anduich_get_all_field_data()don't runuich/pre_load_fieldoruich/load_field, and on the free plan they still return values from Pro field types. Useuich_field_value()for each field when your filters or the Pro check must apply. - Fields on Add New User aren't saved. Use
user_form == register. - Export and import lose the description, the Active setting, and inactive groups.
- Dates keep the format they were saved in.
- Multisite: only user values include the site ID. Definitions are per site.
- WPML: post, term, user, and comment values are copied once to new translations. Options aren't.
- Uninstall removes field values, import backups, the journal, options, and the definition files only when Delete all data on uninstall is on (
uichemy_settings). Posts and post type entries are never deleted.
If It Doesn't Work
Related
Custom Fields Overview
Post types, taxonomies, field groups, and migration in the dashboard.
UiChemy Custom Fields in UiChemy Composer
Show field values with the Custom Field dynamic tags.
Twig
Read fields in a Composer with template tokens.
Set Up AI to WordPress
Connect an AI tool that can use the abilities.