Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Workday Jobs
- Description: Display Workday job postings using Recruiting API v3 with a parameter for the number of jobs.
- Version: 1.0
- */
- // Define your Workday Recruiting API endpoint and credentials here
- $api_endpoint = 'https://api.workday.com/recruiting/v3/jobPostings';
- $api_token = 'your_api_token_or_credentials';
- // Function to fetch and display Workday job postings
- function display_workday_job_postings($atts) {
- global $api_endpoint, $api_token;
- // Shortcode attributes (number of jobs to display)
- $atts = shortcode_atts(array(
- 'count' => 10, // Default number of jobs to display
- ), $atts);
- // Initialize cURL session
- $ch = curl_init();
- // Set cURL options
- curl_setopt($ch, CURLOPT_URL, $api_endpoint);
- curl_setopt($ch, CURLOPT_HTTPGET, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // Set the HTTP headers
- $headers = array(
- 'Authorization: Bearer ' . $api_token, // Use appropriate authentication method
- 'Content-Type: application/json', // Set the content type
- // Add any other headers as needed
- );
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- // Execute the cURL request
- $response = curl_exec($ch);
- // Check for cURL errors
- if (curl_errno($ch)) {
- echo 'Curl error: ' . curl_error($ch);
- }
- // Close cURL session
- curl_close($ch);
- // Process the API response
- if ($response !== false) {
- // Decode the JSON response
- $data = json_decode($response, true);
- // Display job postings
- if (isset($data['jobPostings']) && is_array($data['jobPostings'])) {
- echo '<ul>';
- $count = 0;
- foreach ($data['jobPostings'] as $posting) {
- if ($count < $atts['count']) {
- echo '<li>' . $posting['jobPostingID'] . ': ' . $posting['jobPostingTitle'] . '</li>';
- $count++;
- } else {
- break;
- }
- }
- echo '</ul>';
- } else {
- echo 'No job postings found.';
- }
- } else {
- // Handle the error here
- echo 'Error fetching data from Workday API';
- }
- }
- // Shortcode to display Workday job postings in WordPress with a count parameter
- function workday_job_postings_shortcode($atts) {
- ob_start();
- display_workday_job_postings($atts);
- return ob_get_clean();
- }
- add_shortcode('workday_job_postings', 'workday_job_postings_shortcode');
- ?>
- [workday_job_postings count="X"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement