Intro

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.

In the UI

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:

  1. The field whose values should be displayed in the column.
  2. 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.
  3. If you want the column to be sortable or not.

In PHP

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 UF\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 UF\Location;
use UF\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 );

Support forums

Having trouble and cannot find anything about it in the docs?

Somebody might have already been there.

View the forums