When your website means business.

ACF, CPT, Custom Admin | Type: PHPAdd Columns to Admin CPT Listing

See David Lord site for implementation.

/*-------------------------------------------------------------------------------
	Custom Columns - shown with date custom field
-------------------------------------------------------------------------------*/
function my_page_columns($columns) {
  $columns = array(
	'title' => 'Title',
	'type' => 'Project Type',
	'featured' => 'Featured',
	'date' => 'Date',
	'wps_post_id' => 'ID',
	);
	return $columns;
}
function my_custom_columns($column) {
	global $post;
	if($column == 'trngdate') {
	$startdate = DateTime::createFromFormat('Ymd', get_field('ACF_CUSTOMFIELDNAME'));
	echo $startdate->format('F j, Y');
	}
	if($column == 'type') {
	$projectype = get_field('ACF_CUSTOMFIELDNAME');
	echo $projectype;
	}
	if($column == 'featured') {
	$feat = get_field('ACF_CUSTOMFIELDNAME');
	    if ($feat=='Yes') {
	        echo '✓';
	    }
	}
}
add_filter("manage_edit-CPTNAME_columns", "my_page_columns");
add_action("manage_posts_custom_column", "my_custom_columns");

/*-------------------------------------------------------------------------------
	Sortable Columns
-------------------------------------------------------------------------------*/
function my_column_register_sortable( $columns ) {
	$columns['trngdate'] = 'trngdate';
	return $columns;
}
add_filter("manage_edit-CPTNAME_sortable_columns", "my_column_register_sortable" );

ANOTHER EXAMPLE:

/*-------------------------------------------------------------------------------
	Paintings Custom Columns
-------------------------------------------------------------------------------*/
function paint_columns($columns) {
  $columns = array(
  	'cb' => 'cb-select-all-1',
	'title' => 'Painting Title',
	'decade' => 'Decade',
	'month-year' => 'Month/Year',
	'date' => 'Date',
	'wps_post_id' => 'ID',
	);
	return $columns;
}
function my_custom_columns($column) {
	global $post;
	if($column == 'decade') {
	$thedecade = get_field('paint_decade');
	echo $thedecade;
	}
	if($column == 'month-year') {
	$monthyear = get_field('paint_monthyear');
	echo $monthyear;
	}
}
add_filter("manage_edit-paintings_columns", "paint_columns");
add_action("manage_posts_custom_column", "my_custom_columns");

/*-------------------------------------------------------------------------------
	Sortable Columns
-------------------------------------------------------------------------------*/
function my_column_register_sortable( $columns ) {
	$columns['decade'] = 'decade';
	return $columns;
}
add_filter("manage_edit-paintings_sortable_columns", "my_column_register_sortable" );

Reference Links

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept