Last active
May 3, 2017 14:50
-
-
Save solid-pixel/e646cbf6b5185d2b74794769ed59c703 to your computer and use it in GitHub Desktop.
Add Admin Column showing ACF Post Object's field
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 // remove this tag | |
// ADD NEW COLUMN | |
function JOBDIVISION_columns_head($defaults) { | |
$defaults['division_post_obj'] = 'Division'; // Replace with your column name | |
return $defaults; | |
} | |
// SHOW THE TITLE | |
function JOBDIVISION_columns_content($column_name, $post_ID) { | |
if ($column_name == 'division_post_obj') { | |
if( get_field('division_cpt') ) { // Display only if a post object is specified - replace division_cpt with your custom field | |
$thisJobID = get_field('division_cpt'); // Specify the Post Object slug to grab the linked its ID | |
echo get_the_title($thisJobID); // Now that we've got the ID we can grab any field or custom field we want | |
} | |
} | |
} | |
add_filter('manage_job_posts_columns', 'JOBDIVISION_columns_head'); // Replace 'job' with your CPT slug | |
add_action('manage_job_posts_custom_column', 'JOBDIVISION_columns_content', 10, 2); // Replace 'job' with your CPT slug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment