własne kolumny w WordPress admin panel
Wstawienie kolumn w wykazie postów w panelu administratora bardzo ułatwia nawigację po wpisach, aby dodać kolumny zawierające wybrane custom fields wstawiamy kod w function.php:
add_filter('manage_testimonials_posts_columns' , 'add_testimonials_columns');
function add_testimonials_columns($columns) {
unset($columns['author']);
return array_merge($columns,
array('testimonial-when' => 'date of opinion',
'testimonial-who' => 'author of opinion'
));
}
add_action('manage_testimonials_posts_custom_column' , 'testimonials_custom_columns', 10, 2 );
function testimonials_custom_columns( $column, $post_id ) {
switch ( $column ) {
case 'testimonial-when' :
$opinion_date = get_post_meta($post_id, 'testimonial-when', true);
$opinion_date = new DateTime($opinion_date);
echo $opinion_date->format('d-m-Y');
break;
case 'testimonial-who' :
$opinion_author = get_post_meta($post_id, 'testimonial-who', true);
echo $opinion_author;
break;
}
}
więcej info:
- https://code.tutsplus.com/articles/add-a-custom-column-in-posts-and-custom-post-types-admin-screen–wp-24934
- https://upstatement.com/blog/2014/02/adding-columns-to-the-wordpress-admin-the-easy-way/
- http://scribu.net/wordpress/sortable-taxonomy-columns.html
Hope this helps and happy coding :)
Zobacz jeszcze
CSS Triangles
Trójkąty w css: .arrow-up { width: 0; height: 0; font-size: 0; line-height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;...