Skip to content

Instantly share code, notes, and snippets.

@dylan-k
Forked from jchristopher/functions.php
Created April 15, 2019 19:00
Show Gist options
  • Save dylan-k/68b7543bd3471803d1d1451797e3fe6b to your computer and use it in GitHub Desktop.
Save dylan-k/68b7543bd3471803d1d1451797e3fe6b to your computer and use it in GitHub Desktop.
<?php
function my_find_expired_events( $ids ) {
$args = array(
'post_type' => 'tribe_events',
'nopaging' => true,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => '_EventEndDate',
'value' => date( 'Y-m-d H:i:s' ),
'compare' => '<',
'type' => 'DATETIME',
),
),
);
$expired_events = get_posts( $args );
$ids = array_merge( $ids, $expired_events );
$ids = array_map( 'absint', $ids );
$ids = array_unique( $ids );
return $ids;
}
add_filter( 'searchwp_exclude', 'my_find_expired_events' );
@dylan-k
Copy link
Author

dylan-k commented Apr 15, 2019

You can use this same code to exclude expired events from the Yoast SEO sitemap. You just need a different final line like:
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', 'my_find_expired_events' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment