Warning: DOMDocument::loadHTML(): Attribute width redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

Warning: DOMDocument::loadHTML(): Attribute height redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

Warning: DOMDocument::loadHTML(): Attribute width redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

Warning: DOMDocument::loadHTML(): Attribute height redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

How to create additional columns in the administration panel?


Warning: DOMDocument::loadHTML(): Attribute width redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

Warning: DOMDocument::loadHTML(): Attribute height redefined in Entity, line: 1 in /home/dominik360/domains/360px.pl/public_html/wp-content/plugins/wp-lazy-loaded-images/lazy-loaded-images.php on line 121

If we want to add additional columns in the administration panel, we have to add two functions and use the appropriate commands.
The first command is responsible for adding columns to existing pages and posts. It has several variations depending on whether we want to add this functionality in page editing, posts or custom post type:

add_filter('manage_szkolenia_posts_columns' , 'add_columns'); //stworzy je w edycji Custom Post type Szkolenia
add_filter('manage_posts_columns' , 'add_columns'); //stworzy je w edycji postów
add_filter('manage_pages_columns' , 'add_columns'); //stworzy je w edycji stron

In our case, the function that tells you which columns to add is called add_columns and looks like this:

function add_columns($columns) {
return array_merge( $columns,
array('miasto' => __('Miasto'), //nazwa i tytuł pierwszego pola
'data_szkolenia' => __('Data szkolenia') //nazwa i tytuł drugiego pola
)
);
}

We already have columns? Excellent! Now it would be nice to fill them with something. And here we will use the second functionality:

add_action('manage_szkolenia_posts_custom_column', 'manage_szkolenia_columns', 10, 2);

Similarly to the first example, this can be used for posts, pages or custom post type.
In our case, we created columns using Advaced Custom Fields and the final code looks like this.

function add_columns($columns) {
return array_merge( $columns,
array('miasto' => __('Miasto'),
'data_szkolenia' => __('Data szkolenia')
)
);
}
add_filter('manage_szkolenia_posts_columns' , 'add_columns');
add_action('manage_szkolenia_posts_custom_column', 'manage_szkolenia_columns', 10, 2);

function manage_szkolenia_columns($column_name, $id) {
switch ($column_name) {
case 'miasto':
echo get_field('miasto'); //Jeżeli kolumna jest miasto, wyświetl pole miasto z acf
break;
case 'data_szkolenia':
echo get_field('start'); //Jeżeli kolumna jest data_szkolenia, wyświetl pole start z acf
break;
default:
break;
} // end switch
}

The end result is as follows:

Enjoy your meal!

1 Gwiazdka2 Gwiazdki3 Gwiazdki4 Gwiazdki5 Gwiazdek (Brak ocen)
Loading...

Office address
360px Sp.z.o.o.
ul. Sadowa 10,
41-200 Sosnowiec
Poland

NIP: 6443546391
REGON: 381910184

Address for correspondence
ul. Gwiezdna 8/10,
Sosnowiec 41-218
Poland