Tribe__JSON_LD__Abstract::get_data( mixed $post = null, array $args = array() )
Compile the schema.org event data into an array
Contents
Parameters
- $post
-
(mixed) (Optional) Either a post ID or a WP_post object.
Default value: null
- $args
-
(array) (Optional) An array of arguments to control the returned data.
- 'context'
(string) The value of the@contexttag, defaults to<a href="https://schema.org">https://schema.org</a>
Default value: array()
- 'context'
Return
(array) Either an array containing a post data or an empty array if the post data cannot be generated, the $post parameter is not a valid post ID or object or the data for the post has been fetched already.
Source
File: src/Tribe/JSON_LD/Abstract.php
public function get_data( $post = null, $args = array() ) {
$post_id = Tribe__Main::post_id_helper( $post );
if ( ! $post_id ) {
return array();
}
// This prevents a JSON_LD from existing twice one the same page
if ( $this->exists( $post_id ) && $this->type_exists( $post_id, $this->type ) ) {
return array();
}
$post = get_post( $post_id );
if ( empty( $post->ID ) ) {
return array();
}
$data = (object) array();
// We may need to prevent the context to be triggered
if ( ! isset( $args['context'] ) || false !== $args['context'] ) {
$data->{'@context'} = 'http://schema.org';
}
$data->{'@type'} = $this->type;
$data->name = esc_js( get_the_title( $post ) );
$data->description = esc_js( tribe_post_excerpt( $post ) );
if ( has_post_thumbnail( $post ) ) {
$data->image = wp_get_attachment_url( get_post_thumbnail_id( $post ) );
}
$data->url = esc_url_raw( $this->get_link( $post ) );
$type = strtolower( esc_attr( $this->type ) );
$data = $this->apply_object_data_filter( $data, $args, $post );
// Index by ID: this will allow filter code to identify the actual event being referred to
// without injecting an additional property
return array( $post->ID => $data );
}