Skip to content

Adding Post Type Columns

Paul Ryley edited this page May 23, 2017 · 6 revisions

The Post Type Columns field in the Pollux settings contains the column labels that are shown in the Post Type admin page table.

Built-in columns include:

  • author
  • categories
  • comments
  • date
  • media
  • slug
  • thumbnail
  • title

The slug column displays the slug of the post_type.

The media column displays a count of images uploaded in a meta-box with an ID of "media".

The thumbnail column display a thumbnail of the featured image if set.

All other built-in columns should be self-explanatory.

To add your own custom column

  1. First you must add the column to the Post Type columns key in the "Post Types" field:
columns:
  - title
  - my_awesome_column
  - date
  1. Next you must add the custom column label in the "Post Type Columns" field:
my_awesome_column: Awesome!
  1. Finally, you must create a special file called pollux-hooks.php and place it either in your root web directory, or in the wp-content directory. Once you have created the file, add a custom filter in it to populate the custom column with a value:
add_filter( 'pollux/post_type/column/my_awesome_column', function( $value, $post_id ) {
    return PostMeta::get( 'awesome_value', [
        'fallback' => $value,
    ]);
});