Last active
April 25, 2025 13:46
-
-
Save morgyface/24b0b0d1eef5d4372584445deb769956 to your computer and use it in GitHub Desktop.
WordPress | Advanced Custom Fields | Create custom columns within admin for a custom post type using ACF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change the columns for the releases list screen | |
function change_columns( $cols ) { | |
$cols = array( | |
'cb' => '<input type="checkbox" />', | |
'featimg' => 'Featured Image', | |
'excerpt' => 'Excerpt?', | |
'title' => 'Title', | |
'artist' => 'Artist', | |
'catno' => 'Cat#', | |
'categories' => 'Category', | |
'tags' => 'Tags', | |
'date' => 'Release Date' | |
); | |
return $cols; | |
} | |
function custom_columns( $column ) { | |
global $post; | |
if( $column == 'featimg' ) { | |
if ( has_post_thumbnail() ) { | |
the_post_thumbnail( 'thumbnail' ); | |
} else { | |
echo '-'; | |
} | |
} | |
if( $column == 'excerpt' ) { | |
if ( has_excerpt() ) { | |
echo '✓'; | |
} else { | |
echo '-'; | |
} | |
} | |
if( $column == 'artist' ) { | |
$artist = get_field('artist'); | |
if( $artist ) { | |
echo $artist; | |
} else { | |
echo '-'; | |
} | |
} | |
if( $column == 'catno' ) { | |
$catno = get_field('cat_number'); | |
if( $catno ) { | |
echo $catno; | |
} else { | |
echo '-'; | |
} | |
} | |
} | |
add_action( "manage_releases_posts_custom_column", "custom_columns", 10, 2 ); | |
add_filter( "manage_releases_posts_columns", "change_columns" ); |
Thanku for this help..
But I wants to know how we give file custom field in table which is URL of pdf and opne in new tab.
Doesn't work after applying a filter admin panel.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfectly! Great job