Created
May 22, 2024 05:20
-
-
Save iamrealfarhanbd/b7f2742f290d24a073c5f5114540e8d0 to your computer and use it in GitHub Desktop.
Modify Ninja Tables Data: Apply Filter and Limit in ninja_tables_get_public_data Filter Hook
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
add_filter('ninja_tables_get_public_data', function ($data, $tableId) { | |
// Set the limit and filter name here (you can adjust these values as needed) | |
$limit = Your_Limit_Value; | |
$filter_name = 'Your_Filter_Key_Word'; | |
// Check if the current table ID matches the targeted table ID | |
if ($tableId == 426) { // Replace 426 with the actual table ID | |
// Apply the filter first | |
$filtered_data = array_filter($data, function ($row) use ($filter_name) { | |
return $row['title'] == $filter_name; // Replace 'title' with the actual column key to filter | |
}); | |
// Apply the limit | |
$limited_data = array_slice($filtered_data, 0, $limit); | |
// Return the limited and filtered data | |
return $limited_data; | |
} | |
// Return the original data if the table ID doesn't match | |
return $data; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment