I have the following function which is working perfectly for my ‘video’ custom post type to display customized columns in the dashboard.
I have decided the way my plugin will work is to have custom post types created dynamically so I no longer know the exact name of the custom post type and I would like to apply this filter to all custom post type if possible.
function populate_columns( $column ) { // populate the custom columns
if ( 'thumbnail' == $column ) {
$thumb_array = array('post_type' => 'video');
$thumbnails = get_posts($thumb_array);
if ( has_post_thumbnail($thumbnail->ID)) {
echo '<a href="' . get_edit_post_link( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">'; // link thumbnail to edit page
echo get_the_post_thumbnail($thumbnail->ID, array(100,100));
echo '</a>';
}
}
elseif ( 'duration' == $column ) {
$duration_array = array ('post_type'=> 'video');
$duration = get_post_meta( get_the_ID(), '_my_meta_duration', true );
if ($duration != '') {
echo $duration . ' mins';
}
}
}
add_action( 'manage_video_posts_custom_column', 'populate_columns' );
I have been going over these two examples from the codex page for get_post_types but I have not been able to figure out how to implement the post_types array into my function.
The call to get post types returns the registered post types.
<?php $post_types=get_post_types(); ?>
Output a list all registered post types
<?php
$post_types=get_post_types('','names');
foreach ($post_types as $post_type ) {
echo '<p>'. $post_type. '</p>';
}
?>