Make it easy to find events with certain characteristics -- demo/preview: http://cl.ly/1b000a253K1l
<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_with_website_url', 50 );
function events_with_website_url( $content ) {
// only display our results on the home page (won't appear if is_home()
if ( ! is_front_page() ) {
return $content;
}
$find = '_EventURL';
$args = array(
'post_type' => 'tribe_events',
// 'post_status' => 'any',
'posts_per_page' => -1,
'orderby' => 'ID',
// 'order' => 'ASC',
'fields' => 'ids', // just the post ID
'meta_query' => array(
array(
'key' => $find,
),
),
);
$ids = get_posts( $args );
$output = '';
if( ! empty( $ids ) ) {
$output .= PHP_EOL . 'events_with_website_url: ';
foreach( $ids as $key => $value ) {
// $output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links
$output .= sprintf( '<a href="/?p=%1$s">%1$s</a>', $value ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value !== end( $ids ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
}
$content = $output . $content;
return $content;
}<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_with_ticket', 50 );
function events_with_ticket( $content ) {
// only display our results on the home page -- won't appear if is_home()
if ( ! is_front_page() ) {
return $content;
}
global $wpdb;
// escape _ wildcards to be literals
$event_ids_w_tickets = $wpdb->get_col( "
SELECT DISTINCT meta_value
FROM $wpdb->postmeta
WHERE meta_key LIKE '\_tribe\_%\_for\_event'
ORDER BY meta_value ASC"
);
if ( empty( $event_ids_w_tickets ) ) {
return $content;
} else {
rsort( $event_ids_w_tickets );
}
$output = PHP_EOL . 'events_with_ticket: ';
foreach( $event_ids_w_tickets as $key => $value ) {
// $output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links
$output .= sprintf( '<a href="/?p=%1$s">%1$s</a>', $value ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value !== end( $event_ids_w_tickets ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
$content = $output . $content;
return $content;
}
<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_with_recurrence', 50 );
function events_with_recurrence( $content ) {
// only display our results on the home page (won't appear if is_home()
if ( ! is_front_page() ) {
return $content;
}
$find = '_EventRecurrence'; // serialized array if exists
$args = array(
'post_type' => 'tribe_events',
// 'post_status' => 'any',
'posts_per_page' => -1,
'orderby' => 'ID',
// 'order' => 'ASC',
'fields' => 'ids', // just the post ID
'meta_query' => array(
array(
'key' => $find, // serialized array if exists
),
),
);
$ids = get_posts( $args );
$output = '';
if( ! empty( $ids ) ) {
$recurrence_ids = array();
foreach( $ids as $key => $value ) {
$temp_parent_id = 0;
if( function_exists( 'tribe_is_recurring_event' ) ) { // https://theeventscalendar.com/function/tribe_is_recurring_event/
if( tribe_is_recurring_event( $value ) ) {
$temp_parent_id = wp_get_post_parent_id( $value );
if ( ! empty( $temp_parent_id ) ) {
$recurrence_ids[] = $temp_parent_id; // the main post of the recurrence series -- not sure how it'd work for a post broken out from its recurrence series
}
}
}
}
if( ! empty( $recurrence_ids ) && is_array( $recurrence_ids ) ) {
$recurrence_ids = array_unique( $recurrence_ids, SORT_NUMERIC );
$output .= PHP_EOL . 'events_with_recurrence: ';
foreach( $recurrence_ids as $key_r => $value_r ) {
if ( empty( $value_r ) ) { // do not want a Post ID of zero
//continue;
}
$output .= sprintf( '<a href="%s">%s</a> (<a href="%s">edit</a>)', get_permalink( $value_r ), $value_r, get_edit_post_link( $value_r ) ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value_r !== end( $recurrence_ids ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
}
}
$content = $output . $content;
return $content;
}
<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_with_featured_image', 50 );
function events_with_featured_image( $content ) {
// only display our results on the home page -- won't appear if is_home()
if ( ! is_front_page() ) {
return $content;
}
$args = array(
'post_type' => 'tribe_events',
// 'post_status' => 'any',
'posts_per_page' => -1,
'orderby' => 'ID',
// 'order' => 'ASC',
'fields' => 'ids', // just the post ID
'meta_query' => array(
array(
'key' => '_thumbnail_id', // featured image
//'key' => '_tribe_ticket_header', // WooCommerce Tickets header image
),
),
);
$ids = get_posts( $args );
$output = '';
if( ! empty( $ids ) ) {
$output .= PHP_EOL . 'events_with_featured_image: ';
foreach( $ids as $key => $value ) {
// $output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links
$output .= sprintf( '<a href="/?p=%1$s">%1$s</a>', $value ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value !== end( $ids ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
}
$content = $output . $content;
return $content;
}
<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_with_cost', 50 );
function events_with_cost( $content ) {
// only display our results on the home page -- won't appear if is_home()
if ( ! is_front_page() ) {
return $content;
}
$args = array(
'post_type' => 'tribe_events',
// 'post_status' => 'any',
'posts_per_page' => -1,
'orderby' => 'ID',
// 'order' => 'ASC',
'fields' => 'ids', // just the post ID
'meta_query' => array(
array(
'key' => '_EventCost',
),
),
);
$ids = get_posts( $args );
$output = '';
if( ! empty( $ids ) ) {
$output .= PHP_EOL . 'events_with_cost: ';
foreach( $ids as $key => $value ) {
// $output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links
$output .= sprintf( '<a href="/?p=%1$s">%1$s</a>', $value ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value !== end( $ids ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
}
$content = $output . $content;
return $content;
}
<?php
// https://gist.github.com/cliffordp/71a343dd9956b1303dee
add_filter( 'the_content', 'events_imported_by_ical_importer', 50 );
function events_imported_by_ical_importer( $content ) {
// only display our results on the home page -- won't appear if is_home()
if ( ! is_front_page() || ! function_exists( 'tribe_get_events' ) ) {
return $content;
}
$find = '_uid'; // iCal UID
$args = array(
'post_type' => 'tribe_events',
// 'post_status' => 'any',
'posts_per_page' => -1,
'orderby' => 'ID',
// 'order' => 'ASC',
'fields' => 'ids', // just the post ID
'meta_query' => array(
array(
'key' => $find,
),
),
);
$ids = get_posts( $args );
$output = '';
if( ! empty( $ids ) ) {
$output .= PHP_EOL . 'events_imported_by_ical_importer: ';
foreach( $ids as $key => $value ) {
// $output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links
$output .= sprintf( '<a href="/?p=%1$s">%1$s</a>', $value ); // post links
// add comma if not last in array (this method only works for arrays with unique values)
if( $value !== end( $ids ) ) {
$output .= ', ' . PHP_EOL;
}
}
$output .= PHP_EOL;
$output .= '<br><br>';
}
$content = $output . $content;
return $content;
}