WordPress: Custom post type admin columns using advanced custom fields data
/*-------------------------------------------------------------------------------
Custom Columns
http://goo.gl/rqKTyP
-------------------------------------------------------------------------------*/
add_filter('manage_clients_posts_columns', 'gig_grind_client_table_head');
function gig_grind_client_table_head( $columns ) {
$columns['title'] = 'Business Name';
$columns['client_phone'] = 'Phone Number';
$columns['client_email'] = 'Email Address';
$columns['project_rate'] = 'Hourly Rate';
$columns['client_status'] = 'Client Status';
unset($columns['date']);
return $columns;
}
add_action( 'manage_clients_posts_custom_column', 'gig_grind_client_table_content', 10, 2 );
function gig_grind_client_table_content( $column_name, $post_id ) {
if( $column_name == 'client_phone' ) {
$client_phone = get_post_meta( $post_id, 'client_phone_number', true );
echo $client_phone;
}
if( $column_name == 'client_email' ) {
$client_email = get_post_meta( $post_id, 'client_email_address', true );
echo '<a href="mailto:'. $client_email .'">'.$client_email.'</a>';
}
if( $column_name == 'project_rate' ) {
$project_rate = get_post_meta( $post_id, 'project_hourly_rate', true );
echo $project_rate;
}
if( $column_name == 'client_status' ) {
$client_status = get_post_meta( $post_id, 'client_status', true );
echo $client_status;
}
}