Guest User

Untitled

a guest
Nov 7th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.05 KB | None | 0 0
  1. <?php
  2. $post_id = get_the_ID(); // Get the current post ID
  3.  
  4. // Get all cloned instances of the 'serverinformation' group
  5. $serverinformation_clones = rwmb_meta('serverinformation', ['multiple' => true], $post_id);
  6.  
  7. // Check if there are any cloned instances
  8. if (!empty($serverinformation_clones)) {
  9.     // Loop through each cloned instance of the 'serverinformation' group
  10.     foreach ($serverinformation_clones as $serverinformation_clone) {
  11.         echo '<div class="server-info">';
  12.  
  13.         // Check if the 'servernamn_taxo' field exists in the cloned instance and if it's an array
  14.         if (isset($serverinformation_clone['servernamn_taxo']) && is_array($serverinformation_clone['servernamn_taxo'])) {
  15.             // Loop through the array of term IDs
  16.             echo '<ul>';
  17.             foreach ($serverinformation_clone['servernamn_taxo'] as $term_id) {
  18.                 $term = get_term($term_id); // Get term data using term ID
  19.                 if ($term && !is_wp_error($term)) {
  20.                     // Output "Servernamn:" label next to the term name
  21.                     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>';
  22.                 }
  23.             }
  24.             echo '</ul>';
  25.         } elseif (isset($serverinformation_clone['servernamn_taxo'])) {
  26.             // Get term data using term ID
  27.             $term = get_term($serverinformation_clone['servernamn_taxo']);
  28.             if ($term && !is_wp_error($term)) {
  29.                 // Output "Servernamn:" label next to the term name
  30.                 echo '<p style="margin-bottom:5px;"><span><b>Servernamn: </b></span><a href="' . get_term_link($term) . '">' . $term->name . '</a></p>';
  31.             }
  32.         } else {
  33.             echo '<p style="margin-bottom:5px;">No server name found for this clone instance.</p>';
  34.         }
  35.  
  36.         // Check if the 'server_ip' field exists in the cloned instance
  37.         if (isset($serverinformation_clone['server_ip'])) {
  38.             // Output the value of the 'server_ip' field
  39.             echo '<p style="margin-bottom:5px;"><span id="serverip"><b>Server IP:</b></span>' . $serverinformation_clone['server_ip'] . '</p>';
  40.         }
  41.  
  42.         // Add the 'servertyp' radio field here
  43.         if (isset($serverinformation_clone['servertyp'])) {
  44.             $servertyp_value = $serverinformation_clone['servertyp'];
  45.             echo '<p style="margin-bottom:5px;"><span id="servertyp"><b>Servertyp:</b></span> ' . esc_html($servertyp_value) . '</p>';
  46.         }
  47.  
  48.         // Check if the 'server_kommun' field exists in the cloned instance
  49.         if (isset($serverinformation_clone['server_kommun'])) {
  50.             if (is_array($serverinformation_clone['server_kommun'])) {
  51.                 echo '<p style="margin-bottom:5px;"><span id="kommun"><b>Tillhör kommun:</b></span> ' . implode(', ', $serverinformation_clone['server_kommun']) . '</p>';
  52.             } else {
  53.                 echo '<p style="margin-bottom:5px;">Tillhör kommun: ' . $serverinformation_clone['server_kommun'] . '</p>';
  54.             }
  55.         }
  56.  
  57.         // Check if the 'os_version' field exists in the cloned instance
  58.         if (isset($serverinformation_clone['os_version'])) {
  59.             if (is_array($serverinformation_clone['os_version'])) {
  60.                 echo '<p style="margin-bottom:5px;"><span id="osversion"><b>OS Version:</b></span> ' . implode(', ', $serverinformation_clone['os_version']) . '</p>';
  61.             } else {
  62.                 echo '<p style="margin-bottom:5px;">OS Version: ' . $serverinformation_clone['os_version'] . '</p>';
  63.             }
  64.         }
  65.  
  66.         // Check if the 'driftforvaltare' field exists in the cloned instance
  67.         if (isset($serverinformation_clone['driftforvaltare'])) {
  68.             if (is_array($serverinformation_clone['driftforvaltare'])) {
  69.                 $driftforvaltare_names = array_map(function($user_id) {
  70.                     $user_info = get_userdata($user_id); // Get user data using user ID
  71.                     return ($user_info) ? $user_info->display_name : '';
  72.                 }, $serverinformation_clone['driftforvaltare']);
  73.                 echo '<p style="margin-bottom:5px;"><span id="driftforvaltare"><b>Driftförvaltare:</b></span> ' . implode(', ', $driftforvaltare_names) . '</p>';
  74.             } else {
  75.                 $user_info = get_userdata($serverinformation_clone['driftforvaltare']);
  76.                 if ($user_info) {
  77.                     echo '<p style="margin-bottom:5px;">Driftförvaltare: ' . $user_info->display_name . '</p>';
  78.                 }
  79.             }
  80.         }
  81.  
  82.         // Display the 'serverinformation' text field after all the other items
  83.         if (isset($serverinformation_clone['serverinformation'])) {
  84.             echo '<p style="margin-bottom:5px;"><b>Övrig serverinfo:</b> ' . esc_html($serverinformation_clone['serverinformation']) . '</p>';
  85.         }
  86.  
  87.         echo '</div>'; // Close server-info div
  88.     }
  89. } else {
  90.     echo 'No cloned instances found.';
  91. }
  92. ?>
  93.  
Advertisement
Add Comment
Please, Sign In to add comment