Skip to content

Return Types

A complete reference of what each field type returns when retrieved with onemeta_get_meta() or onemeta_get_user_meta().

Field Return Types

Every field type returns a specific PHP type when retrieved. This reference covers what to expect from each field so you can write reliable template code.


Quick Reference Table

Field TypePHP TypeExample Return Value
Textstring"Hello World"
Textareastring"Line one\nLine two"
URLstring"https://example.com"
Emailstring"hello@example.com"
Datestring"2025-12-25"
Togglestring"1" (on) or "" (off)
Selectstring"option_value"
Radiostring"option_value"
Button Groupstring"option_value"
Checkboxarray["value1", "value2"]
Imageint123 (attachment ID)
Fileint456 (attachment ID)
Galleryarray[123, 456, 789] (attachment IDs)
Repeaterarray[["key" => "value"], ...]

String Fields

Text, Textarea, URL, Email, and Date all return plain strings. Always escape before output:

php

$value = onemeta_get_meta( get_the_ID(), 'field_key' );

echo esc_html( $value );   // For text content
echo esc_url( $value );    // For URLs
echo esc_attr( $value );   // Inside HTML attributes

Toggle Field

Returns "1" when on and "" (empty string) when off. It does not return a boolean.

php

$toggle = onemeta_get_meta( get_the_ID(), 'is_featured' );

// Correct — strict comparison
if ( $toggle === '1' ) {
    echo 'Featured';
}

// Incorrect — do not use loose truthiness check
if ( $toggle ) { ... } // This works BUT is misleading — use === '1' for clarity

Choice Fields (Select, Radio, Button Group)

All return the selected choice value as a string — not the label.

php

$status = onemeta_get_meta( get_the_ID(), 'project_status' );
// Returns: "active", "completed", or "archived" — whatever value you set in choices

echo esc_html( $status );

Checkbox Field

Returns an array of selected values. Always check is_array() first.

php

$tags = onemeta_get_meta( get_the_ID(), 'project_tags' );

if ( is_array( $tags ) && ! empty( $tags ) ) {
    foreach ( $tags as $tag ) {
        echo '<span>' . esc_html( $tag ) . '</span>';
    }
}

Image and File Fields

Both return an integer — the WordPress attachment ID.

php

$image_id = onemeta_get_meta( get_the_ID(), 'hero_image' );

if ( ! empty( $image_id ) ) {
    echo wp_get_attachment_image( $image_id, 'large' );
}

Gallery Field

Returns an indexed array of attachment IDs (integers).

php

$gallery = onemeta_get_meta( get_the_ID(), 'photo_gallery' );

if ( is_array( $gallery ) && ! empty( $gallery ) ) {
    foreach ( $gallery as $image_id ) {
        echo wp_get_attachment_image( $image_id, 'medium' );
    }
}

Repeater Field

Returns an array of associative arrays — one per row, keyed by sub-field key.

php

$items = onemeta_get_meta( get_the_ID(), 'team_members' );

if ( is_array( $items ) && ! empty( $items ) ) {
    foreach ( $items as $item ) {
        echo esc_html( $item['name'] ?? '' );
        echo esc_html( $item['role'] ?? '' );
    }
}

Default Values

All helper functions accept an optional third parameter as a default:

php

// Returns 'Untitled' if hero_title has never been saved
$title = onemeta_get_meta( get_the_ID(), 'hero_title', 'Untitled' );

// Returns [] if gallery has never been saved
$gallery = onemeta_get_meta( get_the_ID(), 'gallery', [] );

The default is only returned when the field has never been saved. A saved empty string returns an empty string — not the default.

On This Page