Created
February 27, 2023 01:11
-
-
Save pedrohenriqueromio/e4afd1e8616abe3a5b86491819805d9a to your computer and use it in GitHub Desktop.
This file contains 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 | |
$post_type = 'my_cpt'; | |
// Register the columns. | |
add_filter( "manage_{$post_type}_posts_columns", function ( $defaults ) { | |
$defaults['custom-one'] = 'Custom One'; | |
$defaults['custom-two'] = 'Custom Two'; | |
return $defaults; | |
} ); | |
// Handle the value for each of the new columns. | |
add_action( "manage_{$post_type}_posts_custom_column", function ( $column_name, $post_id ) { | |
if ( $column_name == 'custom-one' ) { | |
echo 'Some value here'; | |
} | |
if ( $column_name == 'custom-two' ) { | |
// Display an ACF field | |
echo get_field( 'my_acf_field', $post_id ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment