Skip to content

nxt/format_value — Change a Field Value Before It Is Displayed

Table of Contents

nxt/format_value runs every time a field value is read for display. It is where you change how a value comes out without changing what is stored.

What It Does

The filter receives the formatted value, the field definition and the object ID. Whatever you return is what the template gets.

Before You Start

  • Nexter Extension 4.9.0 or later with Content Fields enabled.
  • Somewhere to add PHP — a child theme’s functions.php, a small plugin, or a Nexter code snippet.
  • You know the field or post type key you want to affect.

Filter a Displayed Value

  1. Add a filter on nxt/format_value with three arguments.
The Presentation tab, where the built-in display settings live
  1. Test $field['name'] so the change applies only to the field you mean.
  1. Return the original $value unchanged for everything else.
  1. Load a post that has the field and confirm the output changed.

When to Use It

  • Adding a currency symbol or unit without storing it.
  • Falling back to a site-wide default when a post leaves a field empty.
  • Normalising a value that was imported inconsistently.

Display the Value

Formatting a price for display, leaving the stored number alone:

<?php
add_filter( 'nxt/format_value', function ( $value, $field, $object_id ) {
    if ( 'price' !== $field['name'] || '' === $value ) {
        return $value;   // always return the original
    }
    return '&pound;' . number_format_i18n( (float) $value );
}, 10, 3 );

Limitations

  • This changes display only. The stored value is untouched, so sorting and meta_query still see the raw value.
  • It runs on every read. Keep the callback cheap.
  • It does not run for nxt_field_value_raw(), which is the point of that function.

Troubleshooting

Every field changed, not just mine

The $field['name'] test is missing or wrong. Return $value untouched for fields you are not targeting.

Values disappeared

A code path in the callback returns nothing. Every branch must return a value.

Related Docs

Share your Thoughts

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!