Last active
September 6, 2019 12:10
-
-
Save ckanitz/1accb06ce62ffdec3be583eff5a219f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file houses the class that Extends the Yoast Schema Graph for course events | |
* | |
* @package ef/inc | |
*/ | |
if ( interface_exists( 'WPSEO_Graph_Piece' ) ) { | |
/** | |
* The class that extends WPSEO_Graph_Piece to display event schema for courses. | |
*/ | |
class Schema_Event_Frontpage implements WPSEO_Graph_Piece { | |
/** | |
* A value object with context variables. | |
* | |
* @var WPSEO_Schema_Context | |
*/ | |
private $context; | |
/** | |
* Schema_Event constructor. | |
* | |
* @param WPSEO_Schema_Context $context Value object with context variables. | |
*/ | |
public function __construct( WPSEO_Schema_Context $context ) { | |
$this->context = $context; | |
} | |
/** | |
* Determines whether or not a piece should be added to the graph. | |
* | |
* @return bool | |
*/ | |
public function is_needed() { | |
global $wp_query; | |
if ( is_front_page() ) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Adds our Event piece of the graph. | |
* | |
* @return array $graph Event Schema markup | |
*/ | |
public function generate() { | |
$data = array(); | |
$meta_query = array( | |
array( | |
'key' => '_EventEndDate', | |
'value' => date( 'Y-m-d H:i:s' ), | |
'compare' => '>=', | |
), | |
); | |
$args = array( | |
'post_type' => 'tribe_events', | |
'posts_per_page' => 10, | |
'meta_query' => $meta_query, | |
'orderby' => 'meta_value', | |
); | |
$upcoming_events = new WP_Query( $args ); | |
if ( $upcoming_events->have_posts() ) { | |
while ( $upcoming_events->have_posts() ) { | |
$upcoming_events->the_post(); | |
$args = array(); | |
$tribe_data = Tribe__Events__JSON_LD__Event::instance()->get_data( $post ); | |
// Strip the post ID indexing before returning. | |
$tribe_data = array_values( $tribe_data ); | |
if ( count( $tribe_data ) > 0 ) { | |
$_tribe_data = (array) $tribe_data[0]; | |
$data[] = $_tribe_data; | |
} | |
} | |
} | |
wp_reset_query(); | |
return $data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment