-
Notifications
You must be signed in to change notification settings - Fork 8
Administration columns
Some of the locations of Ultimate Fields allow you to add additional columns to the listings of the types they are associated with.
- The Post Type location allows you to add columns to post listing screens.
- The Taxonomy location allows you to add columns to taxonomy lists.
- The User location allows you to add additional columns to user lists.
Adding additional columns to those listings/tables can let users get a better and quicker overview without having to enter idividual editing screens. For example, if you create a new Event post type, it would probably have "Event Start" and "Event End" fields associated with it. Since this is core information about the event, you might want to display it in the table.
go to the "Columns" tab of any of the supported locations and add the columns, which you would like to use. For each column you can select:
- The field whose values should be displayed in the column.
- A position:
- append will add the column at the end of the table
- prepend will add the column in the absolute beginning of the table
- after title will display the column with high priority after the title, but will not move the title to the right.
- If you want the column to be sortable or not.
You can use the admin_columns
argument for the $args
array or the add_admin_columns
method of the location. Both of them expect a new Ultimate_Fields\Admin_Column
instance.
To create a new column you can use the static create
method:
$column = Admin_Column::create( 'event_start' );
Then you can use the following methods to set it up:
// Make the column sortable
$column->sortable();
// Set the position to `prepend`
$column->preprend();
// Set the position to `after_title`
$column->append_after_title();
// Use a custom callback to format the output of the column
$column->set_callback( 'my_formatting_function' );
function my_formatting_function( $value, $location, $item_id ) {
// Do some formatting here
return $value;
}
Each of the methods returns the column, so you can keep on using method chaining.
A complete example would look like this:
$container->add_location( 'post_type', 'event', array(
'admin_columns' => array(
Admin_Column::create( 'event_start' )
->append_after_title()
->sortable(),
Admin_Column::create( 'event_end' )
->append_after_title()
->sortable()
)
));
or like this if you are manually creating the location:
use Ultimate_Fields\Location;
use Ultimate_Fields\Admin_Column;
$location = new UF\Location\Post_Type( 'event' );
$location->add_admin_columns(array(
Admin_Column::create( 'event_start' )
->append_after_title()
->sortable(),
Admin_Column::create( 'event_end' )
->append_after_title()
->sortable()
));
$container->add_location( $location );
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