-
Notifications
You must be signed in to change notification settings - Fork 8
Attachment
Internally all user-uploaded files in WordPress are called Attachments.
Ultimate FIelds allows you to add additional fields to all attachment types with the fields being visible in the media popup through the Attachment location.
To add fields to attachments with the the Administration Interface, please follow these steps:
- If you are not on the "Add Container" screen already, locate the "Ultimate Fields" section in the administration area and click the "Add New" button on the top (next to the "Containers" title).
- Locate the "Locations" box.
- Click "Attachments" from the bottom row.
- Select what file types you'd like to show the fields on.
The attachment location in Ultimate Fields is handled by the Ultimate_Fields\Location\Attachment
class. In order to use it, you can either create the new location object manually or let the container do it for you.
The constructor of the class looks like this:
public function __construct( $file_types = array() ) {
$file_types
is an array, which allows you to manually select what file types to use the location with. It expects either a single value or multiple ones, containing MIME Types.
You can add multiple values and/or exclude values by appending a minus sign in front of them.
Create a new location by using the new
keyword and assign it to the container through the add_location()
method.
use Ultimate_Fields\Container;
use Ultimate_Fields\Location\Attachment;
$container = Container::create( 'attachment-data' );
// Create a new location and add definitions to it
$location = new Attachment(array( 'image/jpg' ));
// Once the location has been fully set up, add it to the container
$container->add_location( $location );
You can also let the container create the location for you by providing the "attachment"
string as the first parameter to add_location()
. The second parameter for the method would be the MIME types.
use Ultimate_Fields\Container;
Container::create( 'attachmentdata' )
->add_location( 'attachment', array( 'image/jpeg' ) );
To retrieve the values of fields, associated with the attachment location, you can skip the $type
parameter for *_value
functions. You simply need to provide a number (int
), containing the attachment ID (ex. get_value( 'copyrights_holder', 10 )
).
The reason that you do not have to specifiy a particular type is that WordPress stores attachments as posts and Ultimate Fields uses the same datastore for both posts and attachments.
Example:
$copyrights_holder = get_value( 'copyrights_holder', $image->ID );
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials