Modify columns
Add Columns
use PostTypes\PostType;
use PostTypes\Columns;
class Books extends PostType
{
//...
/**
* Set the PostTypes admin columns.
*
* @return array
*/
public function columns( Columns $columns ): Columns
{
// Add a new price column.
$columns->add( 'price' )
// Set the label.
->label( __( 'Price', 'my-text-domain' ) )
// Position the column after the title column.
->after( 'title' )
// Set the populate callback.
->populate( function( $post_id ) {
echo '$' . get_post_meta( $post_id, '_price', true );
} )
// Set the sort callback.
->sort( function( WP_Query $query ) {
$query->set( 'meta_key', 'price' );
$query->set( 'orderby', 'meta_value_num' );
} );
return $columns;
}
}Modify a column
Position Columns
Populate Columns
Sortable Columns
Remove Columns
Whitelist Columns
Low-level API
Last updated