---
title: "File Field in WordPress"
url: https://nexterwp.com/docs/wordpress-file-field/
date: 2026-11-12
modified: 2026-11-12
lang: en
author: "Aditya Sharma"
description: "A file field lets an editor attach a document — a brochure, a spec sheet, a price list — from the media library, so it can be offered as a..."
image: https://nexterwp.com/wp-content/uploads/2026/09/wordpress-file-field-1024x519.jpg
word_count: 433
---

# File Field in WordPress

## Key Takeaways

- Nexter Extension stores a file field as a reference to a media library attachment, and Return Format can give the attachment ID, the URL, or an array with the filename, size, and MIME type.
- Nexter Extension 4.9.0 exposes file field settings across four tabs: General, Validation, Presentation, and Conditional Logic, with options such as Required, Allowed File Types, Minimum, Maximum, Instructions, Wrapper Attributes, and Conditional Logic.
- Nexter Extension limits a file field to one file per field, and the post says a repeater with a file sub-field is the way to handle several files.

A **file field** lets an editor attach a document — a brochure, a spec sheet, a price list — from the media library, so it can be offered as a download without pasting a URL.

## What It Does

The field stores a reference to a media library attachment. **Return Format** decides whether your template gets the attachment ID, the URL, or an array with the filename, size and MIME type.

## Before You Start

- Nexter Extension is installed and active.- Content Fields is enabled under **Nexter → Content Fields**.- You have a field group, or are about to create one.

## Add a File Field

- Go to **Nexter → Content Fields** and open the **Group Fields** tab.

- Open a field group, or create a new one.

- Click **Add Field**.

![A field group open with the Add Field button](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-h-shared-add-field.webp)

- Set **Field Label** to *Brochure (PDF)*. The **Field Name** fills in automatically and is what you use in code.

- Set **Field Type** to **File**.

![The Field Type dropdown listing the available field types](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-h-shared-field-type.webp)

- Choose a **Return Format**.

![The File field settings in the Content Fields builder](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-h-brochure-settings.webp)

- Set **Library** if editors should only pick files uploaded to this post.

- Click **Update**.

![The File field as it appears on the post editing screen](https://nexterwp.com/wp-content/uploads/2026/09/nxt-fields-h-brochure-editor.webp)

## Field Settings

Every field is configured across four tabs. These are the settings this field type offers, read from the field group builder in Nexter Extension 4.9.0.

### General

| Setting | Options | What it does |
| ------- | ------- | ------------ |
| **Return Format** | | *No help text in the UI.* |
| **Library** | | *No help text in the UI.* |

### Validation

| Setting | Options | What it does |
| ------- | ------- | ------------ |
| **Required** | | *No help text in the UI.* |
| **Allowed File Types** | | *No help text in the UI.* |
| **Minimum** | | *No help text in the UI.* |
| **Maximum** | | *No help text in the UI.* |

### Presentation

| Setting | Options | What it does |
| ------- | ------- | ------------ |
| **Instructions** | | *No help text in the UI.* |
| **Wrapper Attributes** | | *No help text in the UI.* |

### Conditional Logic

| Setting | Options | What it does |
| ------- | ------- | ------------ |
| **Conditional Logic** | | *No help text in the UI.* |

## When to Use It

- A brochure or spec sheet on a listing.- A menu or price list on a venue.- A manual or datasheet on a product.

## Display the Value

With an ID returned, build the download link from the attachment:

`<?php
$id = nxt_field_value( 'brochure' );
if ( $id ) {
printf(
'<a href="%s" download>%s</a>',
esc_url( wp_get_attachment_url( $id ) ),
esc_html( get_the_title( $id ) )
);
}`

## Limitations

- The file is stored in the media library, so it is publicly reachable by URL. Do not use a file field for anything that must stay private.- One file per field. For several, use a repeater with a file sub-field.

## Troubleshooting

### The upload is rejected

WordPress blocks file types not on its allowed list. Check the extension is permitted for your site before assuming the field is at fault.

### The link is broken

The attachment was deleted from the media library while the ID remained stored. Check the value resolves before rendering.

## Related Docs

- [Create your first field group](https://nexterwp.com/docs/create-a-field-group-wordpress/)- [Display a field value on the front end](https://nexterwp.com/docs/display-custom-field-value-wordpress/)

## Frequently Asked Questions

**Q: How do I add a file field in WordPress for a brochure or PDF download?**
A: A file field stores a media library attachment, so it works well for a brochure or PDF without pasting a raw URL into content. In Nexter Extension, the field label can be set to something like Brochure (PDF), and the field name is what you use in code. The key choice is Return Format, because it controls whether you get the attachment ID, the URL, or an array with filename, size, and MIME type.

**Q: Why is my WordPress file upload being rejected?**
A: WordPress blocks file types that are not on its allowed list, so a rejected upload usually points to the site’s file-type rules rather than the field itself. That matters because the file field only stores a media library attachment, it does not override WordPress upload restrictions. If the extension is not permitted for your site, the upload will fail before the field can save it.

**Q: What is the best return format for a WordPress file field?**
A: The best return format depends on how you plan to use the value. An ID is the most flexible if you want to build your own download link in PHP, while a URL is simpler when you only need the direct file address. The array option gives extra metadata like filename, size, and MIME type, which is useful when templates need more than just a link.

**Q: Can I use a WordPress file field for private documents?**
A: A file field is a bad fit for private documents because the file lives in the media library and is publicly reachable by URL. That means anyone who has or guesses the link can access it. For anything that must stay private, this setup is not appropriate. It works better for public downloads like brochures, spec sheets, menus, price lists, manuals, or datasheets.

**Q: How do I show a downloadable file link from a WordPress file field?**
A: When the field returns an ID, you can turn that attachment into a download link with `wp_get_attachment_url( $id )` and use `get_the_title( $id )` as the link text. That approach keeps the template tied to the media library record instead of hardcoding a URL. The page’s example also adds `download`, which nudges browsers toward downloading instead of opening inline.

**Q: Why does my WordPress file field link break after I delete media?**
A: A broken link usually means the attachment was deleted from the media library while its ID was still stored in the field. The saved value can still exist even when the actual file record is gone, so rendering blindly will produce a dead link. The safe pattern is to check that the value resolves before outputting it on the front end.
