Skip to content

Instantly share code, notes, and snippets.

@rw1982
Created September 24, 2018 18:42
Show Gist options
  • Save rw1982/ed5e6111d7cd45acb67e067590b5c2f6 to your computer and use it in GitHub Desktop.
Save rw1982/ed5e6111d7cd45acb67e067590b5c2f6 to your computer and use it in GitHub Desktop.
WP Modern Tribe Events Calendar Pro / Past Events Category
<!-- WP Modern Tribe Events Calendar Pro / Auto Publish Past-Date Events to "Past Events" Category, and make Primary Category usin Yoast. This solves the problem of atchiving old Events in Modern Tribe's Events Calendar Pro -->
<!-- Drop this in your single event template or maker a plugin out of this. -->
<!-- PAST EVENTS SET PRIMARY CATEGORY -->
<?php
# Grab the events.
$args = array(
'post_type' => 'tribe_events',
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'operator' => 'NOT IN',
'terms' => array( 106 ),
),
),
);
$eq = new WP_Query( $args );
# "The Loop"
if( $eq->have_posts() ) : while( $eq->have_posts() ) : $eq->the_post();
# The post's ID.
$id = get_the_ID();
# The post's end date.
$end_date = tribe_get_end_date( null, true, 'U' );
# If "now" is after the end date...
if( time() > $end_date ) :
# Add "Past Events" to Post Category.
wp_set_object_terms( $id, 106, 'tribe_events_cat', true );
# Set primary term.
$primaryTermObject = new WPSEO_Primary_Term( 'tribe_events_cat', $id );
$primaryTermObject->set_primary_term( 106 );
# Save primary term.
$primaryTermObjectAdmin = new WPSEO_Primary_Term_Admin();
$primaryTermObjectAdmin->save_primary_terms( $id );
endif;
# End and reset "The Loop"
endwhile; endif;
wp_reset_postdata();
?>
<!-- Thanks To @delster for the help! -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment