array( 'Authorization' => $external_token, 'Plugin' => $pluginToken ), )); // Make another request to get vehicle images $vehicle_images_url = REMOTE_SERVER_URL . '/api/v1/companies/1/vehicles/' . $vehicle_id . '/images'; $vehicle_images_response = wp_remote_get($vehicle_images_url, array( 'headers' => array( 'Authorization' => $external_token, 'Plugin' => $pluginToken ), )); $vehicle_features = REMOTE_SERVER_URL . '/api/v1/companies/1/vehicles/' . $vehicle_id . '/vehiclefeatures'; $vehicle_features_response = wp_remote_get($vehicle_features, array( 'headers' => array( 'Authorization' => $external_token, 'Plugin' => $pluginToken ), )); if ( !is_wp_error($vehicle_details_response) && !is_wp_error($vehicle_images_response) && wp_remote_retrieve_response_code($vehicle_details_response) === 200 && wp_remote_retrieve_response_code($vehicle_images_response) === 200 && wp_remote_retrieve_response_code($vehicle_features_response) === 200 ) { // Decode and print the vehicle details response $vehicle_details = json_decode(wp_remote_retrieve_body($vehicle_details_response), true); $vehicle_features = json_decode(wp_remote_retrieve_body($vehicle_features_response), true); // Decode and print the vehicle images response $vehicle_images = json_decode(wp_remote_retrieve_body($vehicle_images_response), true); // var_dump($searchData); exit; $filters = array( 'body_type' => $vehicle_details['body_type'] ); $similar_vehicles_response = wp_remote_post(REMOTE_SERVER_URL . '/api/v1/wp', array( 'body' => json_encode($filters), // The filters array will be sent in the body of the request 'headers' => array( 'Content-Type' => 'application/json', // Make sure to set the Content-Type header appropriately 'Authorization' => $external_token, 'Plugin' => $pluginToken ), )); if (!is_wp_error($similar_vehicles_response) && wp_remote_retrieve_response_code($similar_vehicles_response) === 200) { $similar_vehicles = json_decode(wp_remote_retrieve_body($similar_vehicles_response), true); if (is_array($similar_vehicles)) { $filtered_vehicles = array_filter($similar_vehicles, function ($vehicle) use ($vehicle_details) { return $vehicle['id_vehicle'] !== $vehicle_details['id_vehicle']; }); } else { $filtered_vehicles = array_filter([], function ($vehicle) use ($vehicle_details) { return $vehicle['id_vehicle'] !== $vehicle_details['id_vehicle']; }); } // echo '
'; // print_r($filtered_vehicles); // echo ''; } // Initialize an empty array to store grouped features $groupedFeatures = array(); // Loop through the features and group them by category foreach ($vehicle_features as $feature) { $category = $feature['category']; // Check if the category key exists in the grouped array if (!array_key_exists($category, $groupedFeatures)) { // If not, create an empty array for the category $groupedFeatures[$category] = array(); } // Add the feature to the corresponding category $groupedFeatures[$category][] = $feature; } // Now $groupedFeatures contains features grouped by category // print_r($groupedFeatures); // echo '
'; // print_r($searchData); // echo ''; } else { echo '
Error retrieving vehicle details or images.
Error: External token not found.
/div>No vehicle found.
Stock #:
", explode(' ', $vehicle_details['comments'])); ?>
Options
+ taxes and fees
7.99 for 12 Months