Modify Columns
Add Columns
use PostTypes\Taxonomy;
use PostTypes\Columns;
class Genres extends Taxonomy
{
//...
/**
* Set the Taxonomy admin columns.
*
* @return Columns
*/
public function columns( Columns $columns ): Columns
{
// Add a new Popularity column.
$columns->add( 'popularity' )
// Set the label.
->label( __( 'Popularity', 'my-text-domain' ) );
// Position the column after the title column.
->after( 'title' )
// Populate the popularity column with term meta.
>populate( function( $term_id ) {
echo get_term_meta( $term_id, '_popularity', true );
} );
// Make the popularity column sortable.
->sort( function( WP_Term_Query $query ) {
$query->query_vars['meta_key'] = '_popularity';
$query->query_vars['orderby'] = 'meta_value_num';
} );
return $columns;
}
}Populate Columns
Sortable Columns
Hide Columns
Column Positioning
Last updated