Skip to content

Instantly share code, notes, and snippets.

@flyingwebie
Last active August 15, 2022 09:41
Show Gist options
  • Save flyingwebie/b4a7cfb3954ab9e0c01745dd1ba58bae to your computer and use it in GitHub Desktop.
Save flyingwebie/b4a7cfb3954ab9e0c01745dd1ba58bae to your computer and use it in GitHub Desktop.
Custom hook to get Custom Fields from Meta Box Settings Page
<?php
// Add a filter for WordPress Filter Hook data source to use
add_filter( 'fws_get_addon_website_hook', 'fws_get_addon_website_callback', 10, 3 );
// My callback function for tag wsf_test_data_source_hook
function fws_get_addon_website_callback( $data_grid, $field_id, $form_object ) {
// Check field ID
if( $field_id !== 137) { return $data_grid; }
// Build new data grid
// Define columns
$data_grid[ 'columns' ] = array(
// Column 1
array( 'label' => __( 'Price' ) ),
// Column 2
array( 'label' => __( 'Label' ) )
// Other columns ...
);
// Define first group
$data_grid[ 'groups' ] = array(
// Group 1
array(
// Label for first group
'label' => __('Checkboxes'),
// Define rows in first group
'rows' => array() // GET THE RECORDS FROM THE FOREACH LOOP
)
// Other groups ...
);
// Get MetaBox Custom Fields - Setting Page -- Master Pricing
$setting_page = "master-pricing";
$field_name = "creation_services"; // <=== CHANGE ME WITH THE RIGHT CUSTOM FIELD ID (METABOX)
// Store the Meta Box Group on a variable
$group = rwmb_meta(
$field_name,
["object_type" => "setting"],
$setting_page
);
// Loop the array with a foreach
foreach ($group as $item) {
// Create a new select row
$data_grid["groups"][0]["rows"][] = array(
// Add one column to the row data
"data" => array(
// Column 1 - Price
$item["price"],
// Column 2 - Label
__($item["service_name"]),
)
);
}
return $data_grid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment