Manage Columns
The Manage_Columns class provides a flexible solution to manage and customize the columns displayed in the WordPress admin for specific post types. By passing a configuration object, you can easily add, rename, and define new columns, making it straightforward to adapt post type views in the admin panel to match project requirements.
This class can be instantiated within the Custom_Post_Type class itself, receiving the βcolumnsβ argument from $this->args['terra_manage_columns']. Alternatively, it can be used outside of this context and will work for both custom post types and native pages.
Key features
Section titled βKey featuresβ- Dynamic Configuration: Adjust columns for specific post types by passing an array of settings.
- ACF Integration: Supports columns using Advanced Custom Fields (ACF) for custom data display.
- Native Column Management: Allows customization of native columns, such as featured images or taxonomy terms.
Examples
Section titled βExamplesβ<?php
// Instantiate the Manage_Columns class with the required configuration.new Manage_Columns((object) array( // Define the post using Custom_Post_Type variable 'post_type' => $this->post_type,
// Specify columns using Custom_Post_Type argument 'columns' => $this->args['terra_manage_columns']));
?>02. Outside Custom_Post_Type class
Section titled β02. Outside Custom_Post_Type classβ<?php
// Instantiate the Manage_Columns class with the required configuration.new Manage_Columns((object) array( // Define the post type (e.g., 'post', 'page', 'custom_post_type') 'post_type' => 'post',
// Specify columns to add and configure 'columns' => array( // Native WordPress column configuration 'featured_image' => array( 'label' => 'Featured Image', // The column header label 'reference' => 'native' // Reference type, can be 'native' or 'acf' ),
// ACF field-based column configuration 'highlighted' => array( 'label' => 'Highlighted', // Custom column label 'reference' => 'acf' // Indicates the data source is ACF ) )));
?>Knowledge Check
Test your understanding of this section
Loading questions...