function tc_get_tickets_count_left($ticket_id) { global $wpdb, $wp_query; $global_quantity_available = 0; $unlimited = false; $quantity_available = get_post_meta($ticket_id, 'quantity_available', true); if (is_numeric($quantity_available)) { $global_quantity_available = $global_quantity_available + $quantity_available; } else { $unlimited = true; } if ($unlimited) { return '∞'; } else { $quantity_sold = tc_get_tickets_count_sold($ticket_id); return abs($global_quantity_available - $quantity_sold); } }
function tickets_sold($atts) { extract(shortcode_atts(array('ticket_type_id' => ''), $atts)); return tc_get_tickets_count_sold($ticket_type_id); }
/** * Prepare a single post output for response. * * @param WP_Post $post Post object. * @param WP_REST_Request $request Request object. * @return WP_REST_Response $data */ public function prepare_item_for_response($post, $request) { $GLOBALS['post'] = $post; setup_postdata($post); // Base fields for every post. $data = array('id' => $post->ID, 'date' => $this->prepare_date_response($post->post_date_gmt, $post->post_date), 'date_gmt' => $this->prepare_date_response($post->post_date_gmt), 'guid' => array('rendered' => apply_filters('get_the_guid', $post->guid), 'raw' => $post->guid), 'modified' => $this->prepare_date_response($post->post_modified_gmt, $post->post_modified), 'modified_gmt' => $this->prepare_date_response($post->post_modified_gmt), 'password' => $post->post_password, 'slug' => $post->post_name, 'status' => $post->post_status, 'type' => $post->post_type, 'tickets_sold' => tc_get_tickets_count_sold($post->ID), 'link' => get_permalink($post->ID)); $schema = $this->get_item_schema(); if (!empty($schema['properties']['title'])) { $data['title'] = array('raw' => $post->post_title, 'rendered' => get_the_title($post->ID)); } if (!empty($schema['properties']['content'])) { if (!empty($post->post_password)) { $this->prepare_password_response($post->post_password); } $data['content'] = array('raw' => $post->post_content, 'rendered' => $post->post_content); // Don't leave our cookie lying around: https://github.com/WP-API/WP-API/issues/1055. if (!empty($post->post_password)) { $_COOKIE['wp-postpass_' . COOKIEHASH] = ''; } } if (!empty($schema['properties']['excerpt'])) { $data['excerpt'] = array('raw' => $post->post_excerpt, 'rendered' => $this->prepare_excerpt_response($post->post_excerpt)); } if (!empty($schema['properties']['author'])) { $data['author'] = (int) $post->post_author; } if (!empty($schema['properties']['featured_image'])) { $data['featured_image'] = (int) get_post_thumbnail_id($post->ID); } if (!empty($schema['properties']['parent'])) { $data['parent'] = (int) $post->post_parent; } if (!empty($schema['properties']['menu_order'])) { $data['menu_order'] = (int) $post->menu_order; } if (!empty($schema['properties']['comment_status'])) { $data['comment_status'] = $post->comment_status; } if (!empty($schema['properties']['ping_status'])) { $data['ping_status'] = $post->ping_status; } if (!empty($schema['properties']['sticky'])) { $data['sticky'] = is_sticky($post->ID); } if (!empty($schema['properties']['template'])) { if ($template = get_page_template_slug($post->ID)) { $data['template'] = $template; } else { $data['template'] = ''; } } if (!empty($schema['properties']['format'])) { $data['format'] = get_post_format($post->ID); // Fill in blank post format. if (empty($data['format'])) { $data['format'] = 'standard'; } } $context = !empty($request['context']) ? $request['context'] : 'view'; $data = $this->filter_response_by_context($data, $context); $data = $this->add_additional_fields_to_object($data, $request); // Wrap the data in a response object. $response = rest_ensure_response($data); $response->add_links($this->prepare_links($post)); /** * Filter the post data for a response. * * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being * prepared for the response. * * @param WP_REST_Response $response The response object. * @param WP_Post $post Post object. * @param WP_REST_Request $request Request object. */ return apply_filters('rest_prepare_' . $this->post_type, $response, $post, $request); }