Last active
July 29, 2024 23:19
-
-
Save mastef/c14bee693246dca79a5ccf44c5ec953f to your computer and use it in GitHub Desktop.
Pods : How to add Custom Admin Table Columns to a Pods ACT
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 | |
/* | |
only important name is the filter name : | |
pods_admin_ui_PODNAME | |
if your pods is called "client" then call it | |
pods_admin_ui_client | |
you can rename all functions to your liking | |
*/ | |
add_filter( 'pods_admin_ui_PODNAME', 'custom_admin_table_columns_for_PODNAME' ); | |
function custom_admin_table_columns_for_PODNAME ( $ui ) { | |
// Adds an admin column called "Info" | |
$ui['fields']['manage']['info'] = array( | |
'label' => 'Info', | |
'sortable' => false, | |
'custom_display' => 'admin_column_info_based_on_PODNAME_id' // function that will be called for every row | |
); | |
// Add an admin column called "Info 2" | |
$ui['fields']['manage']['info2'] = array( | |
'label' => "Info 2", | |
'sortable' => false, | |
'custom_display' => 'admin_column_info2_based_on_PODNAME_id' // function that will be called for every row | |
); | |
return $ui; | |
} | |
function admin_column_info_based_on_PODNAME_id($row) { | |
$results = []; | |
/* custom code here */ | |
$sub = pods( 'other_pod' )->find( null, 1, "some_relationship_id.id='".$row["id"]."'" ); | |
while ( $sub->fetch() ) { | |
$results[] = $sub->field("name"); | |
} | |
/* return valid html */ | |
return implode("<br />", $results); | |
} | |
function admin_column_info2_based_on_PODNAME_id($row) { | |
return $row['id'] . " " . $row['name']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment