---
title: "Custom Field Returns 0 Instead of Empty in WordPress"
url: https://nexterwp.com/docs/custom-field-returns-zero/
date: 2026-11-12
modified: 2026-11-12
lang: en
author: "Aditya Sharma"
description: "A field looks empty in the editor, but your template treats it as having a value — or the reverse. This is the difference between an empty value and a..."
image: https://nexterwp.com/wp-content/uploads/2026/09/custom-field-returns-zero-1024x519.jpg
word_count: 380
---

# Custom Field Returns 0 Instead of Empty in WordPress

## Key Takeaways

- Nexter Pro Extensions 4.8.0 or later is required for Repeater and Relationship, and Nexter Extension alone cannot add either type.
- PHP empty() treats 0 and an empty string the same, so the post compares against an empty string instead of using empty() when reading custom field values.
- A false toggle stores as an empty string, so a meta_query for 0 does not find it; the post says to query for an empty value or use NOT EXISTS.

A field looks empty in the editor, but your template treats it as having a value — or the reverse. This is the difference between an empty value and a zero.

*Repeater* and *Relationship* require **Nexter Pro Extensions 4.8.0** or later. On Nexter Extension alone neither type can be added, and an existing field of either type is locked: the value is kept read-only and is never cleared on save.

## What It Does

Some field types store an unset value as `0` or as an empty string, and PHP’s `empty()` treats both the same. That is what makes the two states look identical in a template when they are not.

## Before You Start

- A template reading a field value.- A post where the field is unset, and one where it genuinely holds zero.

## Test It Correctly

- Compare against an empty string rather than using `empty()`.

- For a reference field — post object, relationship, user — check the target still exists rather than trusting the ID.

![The Field Name box in the builder](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-s-field-name-vs-label.webp)

- For a true/false field, test the value directly. Do not compare against the string `'false'`, which is truthy in PHP.

- If you need to tell “never answered” from “answered no”, use a radio field with three choices instead of a toggle.

## Display the Value

The safe comparisons:

`<?php
$price = nxt_field_value( 'price' );

// wrong: 0 is a real price, but empty() calls it empty
if ( ! empty( $price ) ) { /* ... */ }

// right
if ( '' !== $price && null !== $price ) {
echo esc_html( $price );
}

// a toggle
if ( nxt_field_value( 'featured' ) ) { /* ... */ }`

## Limitations

- A cleared reference field can store `0` and read back as though it holds a value. Check the target exists before using it.- A false toggle is stored as an empty string rather than `0`, so a `meta_query` looking for `0` will not find it. Query for an empty value or use `NOT EXISTS`.

## Troubleshooting

### A price of 0 disappears from my template

`empty()` treats `0` as empty. Compare with `'' !==` instead.

### A relationship renders a blank item

The linked post was deleted and only its ID remains. Guard with `get_post_status()` before rendering.

## Related Docs

- [Why is my custom field empty?](https://nexterwp.com/docs/custom-field-empty-not-showing/)- [Create a field group in WordPress](https://nexterwp.com/docs/create-a-field-group-wordpress/)

## Frequently Asked Questions

**Q: Why does a custom field return 0 instead of empty in WordPress?**
A: Some field types store an unset value as 0 or as an empty string, and PHP empty() treats both the same. That is why a field can look empty in the editor while your template still sees a value. The practical fix is to compare against an empty string instead of relying on empty(), especially when 0 is a real value you want to keep.

**Q: How do I stop a price of 0 from disappearing in my template?**
A: empty() is the usual culprit here because it treats 0 as empty. The safer check is to compare the field against '' and null, then print it only when it is actually set. In the page example, that means a price of 0 stays visible instead of being filtered out by a loose emptiness test.

**Q: What is the safest way to test a WordPress custom field value?**
A: The safest pattern is to compare directly against the value type you expect instead of using empty(). For text-like values, check for '' and null. For true/false fields, test the value directly. For reference fields such as post object, relationship, or user, verify that the target still exists before using the ID.

**Q: How should I handle relationship fields that render blank items?**
A: A blank relationship item usually means the linked post was deleted and only its ID remains. The page recommends guarding with get_post_status() before rendering so you do not output dead references. That matters because a stored ID can look valid even when the actual post no longer exists.

**Q: Can I use Nexter Extension alone for repeater and relationship fields?**
A: Repeater and Relationship require Nexter Pro Extensions 4.8.0 or later. On Nexter Extension alone, neither type can be added, and an existing field of either type becomes locked. The value stays read-only and is never cleared on save, so those fields need the Pro Extensions version to behave normally.

**Q: What should I use instead of a toggle if I need to tell never answered from answered no?**
A: A radio field with three choices is the better fit when you need to separate “never answered” from “answered no.” A true/false field only gives you two states, and the page notes that false is stored as an empty string rather than 0. That makes three-choice radio fields safer when the difference between missing data and a negative answer matters.
