Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $post_id = get_the_ID(); // Get the current post ID
- // Get all cloned instances of the 'serverinformation' group
- $serverinformation_clones = rwmb_meta('serverinformation', ['multiple' => true], $post_id);
- // Check if there are any cloned instances
- if (!empty($serverinformation_clones)) {
- // Loop through each cloned instance of the 'serverinformation' group
- foreach ($serverinformation_clones as $serverinformation_clone) {
- echo '<div class="server-info">';
- // Check if the 'servernamn_taxo' field exists in the cloned instance and if it's an array
- if (isset($serverinformation_clone['servernamn_taxo']) && is_array($serverinformation_clone['servernamn_taxo'])) {
- // Loop through the array of term IDs
- echo '<ul>';
- foreach ($serverinformation_clone['servernamn_taxo'] as $term_id) {
- $term = get_term($term_id); // Get term data using term ID
- if ($term && !is_wp_error($term)) {
- // Output "Servernamn:" label next to the term name
- echo '<li style="width: fit-content; margin-bottom:10px;"><span id="servernamn"><b>Servernamn: </b></span><a class="servernamnbutton3" href="' . get_term_link($term) . '">' . $term->name . '</a></li>';
- }
- }
- echo '</ul>';
- } elseif (isset($serverinformation_clone['servernamn_taxo'])) {
- // Get term data using term ID
- $term = get_term($serverinformation_clone['servernamn_taxo']);
- if ($term && !is_wp_error($term)) {
- // Output "Servernamn:" label next to the term name
- echo '<p style="margin-bottom:5px;"><span><b>Servernamn: </b></span><a href="' . get_term_link($term) . '">' . $term->name . '</a></p>';
- }
- } else {
- echo '<p style="margin-bottom:5px;">No server name found for this clone instance.</p>';
- }
- // Check if the 'server_ip' field exists in the cloned instance
- if (isset($serverinformation_clone['server_ip'])) {
- // Output the value of the 'server_ip' field
- echo '<p style="margin-bottom:5px;"><span id="serverip"><b>Server IP:</b></span>' . $serverinformation_clone['server_ip'] . '</p>';
- }
- // Add the 'servertyp' radio field here
- if (isset($serverinformation_clone['servertyp'])) {
- $servertyp_value = $serverinformation_clone['servertyp'];
- echo '<p style="margin-bottom:5px;"><span id="servertyp"><b>Servertyp:</b></span> ' . esc_html($servertyp_value) . '</p>';
- }
- // Check if the 'server_kommun' field exists in the cloned instance
- if (isset($serverinformation_clone['server_kommun'])) {
- if (is_array($serverinformation_clone['server_kommun'])) {
- echo '<p style="margin-bottom:5px;"><span id="kommun"><b>Tillhör kommun:</b></span> ' . implode(', ', $serverinformation_clone['server_kommun']) . '</p>';
- } else {
- echo '<p style="margin-bottom:5px;">Tillhör kommun: ' . $serverinformation_clone['server_kommun'] . '</p>';
- }
- }
- // Check if the 'os_version' field exists in the cloned instance
- if (isset($serverinformation_clone['os_version'])) {
- if (is_array($serverinformation_clone['os_version'])) {
- echo '<p style="margin-bottom:5px;"><span id="osversion"><b>OS Version:</b></span> ' . implode(', ', $serverinformation_clone['os_version']) . '</p>';
- } else {
- echo '<p style="margin-bottom:5px;">OS Version: ' . $serverinformation_clone['os_version'] . '</p>';
- }
- }
- // Check if the 'driftforvaltare' field exists in the cloned instance
- if (isset($serverinformation_clone['driftforvaltare'])) {
- if (is_array($serverinformation_clone['driftforvaltare'])) {
- $driftforvaltare_names = array_map(function($user_id) {
- $user_info = get_userdata($user_id); // Get user data using user ID
- return ($user_info) ? $user_info->display_name : '';
- }, $serverinformation_clone['driftforvaltare']);
- echo '<p style="margin-bottom:5px;"><span id="driftforvaltare"><b>Driftförvaltare:</b></span> ' . implode(', ', $driftforvaltare_names) . '</p>';
- } else {
- $user_info = get_userdata($serverinformation_clone['driftforvaltare']);
- if ($user_info) {
- echo '<p style="margin-bottom:5px;">Driftförvaltare: ' . $user_info->display_name . '</p>';
- }
- }
- }
- // Display the 'serverinformation' text field after all the other items
- if (isset($serverinformation_clone['serverinformation'])) {
- echo '<p style="margin-bottom:5px;"><b>Övrig serverinfo:</b> ' . esc_html($serverinformation_clone['serverinformation']) . '</p>';
- }
- echo '</div>'; // Close server-info div
- }
- } else {
- echo 'No cloned instances found.';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment