Skip to content

Instantly share code, notes, and snippets.

@MilenFrom
Last active January 8, 2023 06:02
Show Gist options
  • Save MilenFrom/b388dbb930c8937229681fff51737107 to your computer and use it in GitHub Desktop.
Save MilenFrom/b388dbb930c8937229681fff51737107 to your computer and use it in GitHub Desktop.
Oxygen builder function - data output made easy
<?php
function show_meta_boxes($mb_info){
// Get our repeater elements so we can do the foreach in the switch later
$repeater_1 = rwmb_meta('repeater_field_1_id');
$repeater_2 = rwmb_meta('repeater_field_2_id');
// Initialize our return value used to return the data we want depending on the case
$return_data = '';
switch ($mb_info) {
case 'our_case_1':
foreach ($repeater_1 as $value) {
$our_value_1 = $value[our_value_1];
$our_value_2 = $value[our_value_2];
$output .= '<h3>'.$our_value_1.'</h3>
<p>'.$our_value_2.'</p>';
}
$return_data = $output;
break;
case 'our_case_2':
foreach ($repeater_2 as $value) {
$our_value_1 = $value[our_value_1];
$our_value_2 = $value[our_value_2];
$output .= '<h3>'.$our_valie_1.'</h3>
<p>'.$our_value_2.'</p>';
}
$return_data = $output;
break;
}
return $return_data;
}
// Then in Oxygen > Insert data > Advanced - PHP Function Return value > show_meta_boxes / your_case
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment