---
title: "nxt_field_value() — Read a Custom Field Value"
url: https://nexterwp.com/docs/nxt-field-value/
date: 2026-09-14
modified: 2026-11-12
lang: en
author: "Aditya Sharma"
description: "nxt_field_value() is the function you will use most. It returns one field’s value, already formatted according to that field’s return-format setting. What It Does It takes a field name and..."
image: https://nexterwp.com/wp-content/uploads/2026/09/nxt-field-value-1024x519.jpg
word_count: 315
---

# nxt_field_value() — Read a Custom Field Value

## Key Takeaways

- nxt_field_value() returns one field’s value already formatted by that field’s return-format setting, and it reads the current post in the loop when no object is passed.
- Nexter Extension must be installed and active before template functions exist, and the function takes the field name, never the label.
- nxt_field_value() returns null when conditional logic is not met, while nxt_field_value_raw() ignores that; an image field set to return an ID gives an integer, not a URL.

`nxt_field_value()` is the function you will use most. It returns one field’s value, already formatted according to that field’s return-format setting.

## What It Does

It takes a field name and an optional object. With no object it reads the current post in the loop.

## Before You Start

- Nexter Extension is installed and active, so the template functions exist.- You know the field’s **Field Name** — not its label.- You are editing a theme template, a template part, or a plugin.

## Use It in a Template

- Open the template that renders the content — `single.php`, a template part, or a block template.

- Call `nxt_field_value()` with the field **name**.

![The Field Name box, which is the selector this function takes](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-s-field-name-vs-label.webp)

- Check the value before rendering. Some types store an empty value as `0`, so compare with `'' !==` rather than using `empty()`.

- Escape for the context you print into.

## Display the Value

Signature and common uses:

`<?php
// nxt_field_value( string $selector, mixed $object = false )

$price = nxt_field_value( 'price' );
if ( '' !== $price ) {
echo esc_html( number_format_i18n( (float) $price ) );
}

// from another post
$ref = nxt_field_value( 'reference', 123 );

// from a user
$bio = nxt_field_value( 'short_bio', 'user_' . get_current_user_id() );`

## Limitations

- Returns `null` when the field’s conditional logic is not met, even if a value is stored. `nxt_field_value_raw()` ignores that.- Applies the field’s return format. An image field set to return an ID gives you an integer, not a URL.- Takes the field **name**, never the label.

## Troubleshooting

### It returns nothing

Check the name matches the builder exactly, that the post has a value saved, and that the field group’s location rules match the post you are reading from.

### I get an ID where I wanted a URL

That is the field’s **Return Format**. Either change it on the field, or convert in the template — for example `wp_get_attachment_url( $id )`.

## Related Docs

- [Display a custom field value](https://nexterwp.com/docs/display-custom-field-value-wordpress/)- [Field names and field keys](https://nexterwp.com/docs/field-name-vs-label-wordpress/)- [Template functions reference](https://nexterwp.com/docs/nexter-fields-template-functions/)

## Frequently Asked Questions

**Q: Why does nxt_field_value() return nothing even when the field has data saved?**
A: nxt_field_value() can return nothing when the field group’s conditional logic is not met, even if a value is stored. It can also fail if the field name does not match the builder exactly, or if the post you are reading from does not match the field group’s location rules. In practice, this is usually a context problem, not a missing-value problem. The page’s troubleshooting section points to those three checks first.

**Q: How do I use nxt_field_value() in a WordPress template?**
A: nxt_field_value() is meant for theme templates, template parts, or block templates such as single.php. It reads the current post in the loop when you do not pass an object, so it fits naturally inside template code. Nexter Extension provides the template functions used here, and the function takes a field name plus an optional object. That makes it useful when you need one field value without building extra query logic.

**Q: Why am I getting an attachment ID instead of a URL from nxt_field_value()?**
A: That comes from the field’s Return Format. nxt_field_value() applies the field’s return format, so an image field set to return an ID will give you an integer instead of a URL. The fix is either to change the field’s Return Format or convert the ID in your template, for example with wp_get_attachment_url( $id ). This behavior is expected, not a bug in Nexter.

**Q: What should I use as the selector for nxt_field_value(): field name or label?**
A: Use the field name, never the label. The page is explicit about that because labels are for display and names are what the function reads against. Mixing them up is one of the fastest ways to get an empty result even when content exists. If you are unsure which one to use, the related doc on [Field names and field keys](https://nexterwp.com/docs/field-name-vs-label-wordpress/) is the relevant reference.

**Q: How do I safely print a custom field value from nxt_field_value()?**
A: Treat the returned value as raw input until you escape it for the context you print into. The page shows a price example that checks for an empty string first, then formats it with number_format_i18n( (float) $price ) and esc_html(). That matters because some field types store empty values as 0, so using empty() can hide valid data. A strict check like '' !== $price avoids that trap.

**Q: Can nxt_field_value() read custom fields from another post or from a user?**
A: nxt_field_value() accepts an optional object, so it can read beyond the current post in the loop. The page shows two concrete cases: reading from another post with nxt_field_value( 'reference', 123 ) and reading from a user with nxt_field_value( 'short_bio', 'user_' . get_current_user_id() ). That makes it useful when your template needs related content or profile data instead of only the current post.
