Meta Box
Meta Box fields work with CelerSearch through a built-in integration — no
code required. When both plugins are active, your Meta Box fields appear right inside an index's
attribute pickers, and you choose which ones to make searchable, filterable, or sortable with a
checkbox. This includes fields stored in Custom Database Tables (Meta Box's
MB Custom Table extension), which keep values
in dedicated SQL tables instead of wp_postmeta.
Availability
The built-in Meta Box integration is available in CelerSearch 1.7.0 and later. On earlier versions you can still index Meta Box fields with the manual hook recipe below.
Setup
- Activate both plugins — Meta Box (with the MB Custom Table extension, if you use it) and CelerSearch.
- Open your Posts index in CelerSearch → Indices → (your index) → Settings.
- In the Searchable, Filterable, and Sortable attribute pickers you'll now see your Meta Box fields, grouped under "Meta Box · <Field Group>". Enable the ones you want.
- Save, then rebuild the index to backfill existing posts.
That's it. From then on, every post edit re-indexes automatically with the current field values.
Opt-in by design
Nothing is indexed until you enable it. CelerSearch lists your Meta Box fields as choices, but only the fields you tick are added to the search record — so documents stay lean, which matters on large catalogs. A field you never enable is never read or stored.
Custom Database Tables just work
Values are read through Meta Box's own API, so it makes no difference whether a field lives in
wp_postmeta or a dedicated custom table — the same toggle indexes both. At scale this is an
advantage: a custom-table group is a single indexed-row read per post, lighter than the equivalent
wp_postmeta lookups.
Which field types are supported
Meta Box field values are cast to a type the search engine can use, and each type is offered only in the pickers where it makes sense:
| Field types | Searchable | Filterable | Sortable |
|---|---|---|---|
| Text, URL, email, tel, select, radio, button group | ✓ | ✓ | ✓ |
| Textarea, WYSIWYG | ✓ | ✓ | — |
| Date, datetime, time | — | ✓ | ✓ |
| Number, range, slider | — | ✓ | ✓ |
| Checkbox, switch | — | ✓ | ✓ |
| Multi-value / cloneable (checkbox list, multi-select, autocomplete, any cloned field) | ✓ | ✓ | — |
Multi-value fields can't be sorted (the engine can't order on an array), so they're offered as searchable/filterable only. Complex fields — groups, file/image/media, maps, relationships, taxonomy/post/user pickers — aren't indexed automatically; use the manual recipe to shape those into a scalar yourself.
How syncing works
- Rebuild once after enabling fields to backfill existing posts (dashboard, or
wp celersearch reindex). - Edits sync automatically. Meta Box writes its (custom-table or postmeta) values when a post is
saved, and CelerSearch re-indexes the post on
wp_after_insert_post— which fires after the save — so the fresh value is always picked up. No manual step.
Direct-to-table writes
The automatic re-sync keys off the post being saved. If something writes a custom-table value
without re-saving the post (a direct DB or API write), that post won't re-index on its own — run
wp celersearch reindex, or add a custom observer. Normal editing
in wp-admin never hits this.
Advanced: manual control
For computed fields, custom casting, or field types the integration doesn't index, you
can add fields yourself with the same hooks the integration uses. Read the value with Meta Box's API,
rwmb_meta() (not get_post_meta() — only rwmb_meta() resolves custom-table storage), attach
it to the record, then mark it searchable/filterable in the index settings.
// 1. Add a computed / custom-cast Meta Box value to the record.
add_filter( 'celersearch_searchable_post_shared_attributes', function ( $attrs, $post ) {
// Reads from wp_postmeta OR a Meta Box Custom Database Table:
$price = (float) rwmb_meta( 'price', '', $post->ID );
$attrs['price_bracket'] = $price >= 100 ? 'premium' : 'standard'; // derived field
return $attrs;
}, 10, 2 );
// 2. Make it searchable/filterable (setters replace the list — keep the defaults you want).
add_filter( 'celersearch_posts_index_settings', function ( $settings, $index ) {
return $settings
->searchable_attributes( [ 'title:unordered', 'taxonomies:unordered', 'content:unordered', 'price_bracket:unordered' ] )
->filterable_attributes( [ 'taxonomies', 'taxonomies_hierarchical', 'author.display_name', 'type_label', 'status', 'post_id', 'price_bracket' ] );
}, 10, 2 );
Then rebuild once. Note that celersearch_watch_post_meta_keys only reacts to
wp_postmeta writes, so it does not fire for Custom Database Tables — but you don't need it, since
a normal post edit already re-indexes via wp_after_insert_post.
Related
- Indexing hooks — the filters the integration (and the manual recipe) build on
- Sync hooks — real-time sync and
celersearch_watch_post_meta_keys - Custom observers — for direct-to-table writes that skip the post save