Created
February 24, 2015 18:12
-
-
Save andrewlaskey/d7072be41cca60ef7f57 to your computer and use it in GitHub Desktop.
Adding ACF to columns in Wordpress
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
// ADD NEW COLUMNS | |
function custom_columns_head($columns) { | |
$columns = array( | |
'cb' => '<input type="checkbox" />', | |
'title' => 'Title', | |
'custom_field_1' => 'Column Name', | |
'custom_field_2' => 'Column Name', | |
'date' => 'Date' | |
); | |
return $columns; | |
} | |
// SHOW THE CUSTOM FIELD | |
function custom_columns_content($column_name) { | |
global $post; | |
if ($column_name == 'custom_field_1') { | |
$custom_field = get_field('custom_field_1', $post->ID); | |
if ($custom_field) { | |
echo $custom_field; | |
} | |
} | |
if ($column_name == 'custom_field_2') { | |
$custom_field = get_field('custom_field_2', $post->ID); | |
if ($custom_field) { | |
echo $custom_field; | |
} | |
} | |
} | |
//TO ADD NEW COLUMNS TO POSTS | |
add_filter('manage_posts_columns', 'custom_columns_head'); | |
add_action('manage_posts_custom_column', 'custom_columns_content'); | |
//TO ADD NEW COLUMNS TO CUSTOMPOSTTYPE | |
add_filter('manage_customposttype_posts_columns', 'custom_columns_head'); | |
add_action('manage_customposttype_posts_custom_column', 'custom_columns_content'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment