Last active
February 11, 2020 19:49
-
-
Save gugaalves/16edd9ca42e5cc0adee169d6f784bdfb to your computer and use it in GitHub Desktop.
[Plugin] The Events Calendar - Programatically set events as "Featured" when meeting some custom criteria
This file contains hidden or 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 | |
/** | |
* | |
* Custom function setting events as Featured Event when meeting your custom criteria | |
* | |
* @link https://theeventscalendar.com/knowledgebase/k/using-tribe_get_events/ | |
* | |
* Note that you can use all arguments available on WP_Query class => http://codex.wordpress.org/Class_Reference/WP_Query | |
* The Events Calendar exposes some additional arguments that are not normally available but which make life easier when working with events: | |
* start_date is used to indicate the start of the date range you are interested in | |
* end_date is of course what you would use to indicate the end of the date range you are interested in | |
* | |
*/ | |
// Check if the Events Calendar plugin is active | |
function ga_events_calendar_conditional_featured(){ | |
if (is_plugin_active('the-events-calendar/the-events-calendar.php')) { | |
// Example: Retrieve all events in October 2014 | |
$events = tribe_get_events( [ | |
'start_date' => '2020-10-01 00:01', | |
'end_date' => '2020-10-31 23:59', | |
] ); | |
// For each event meeting the criteria, set it as FEATURED EVENT | |
foreach ($events as $event){ | |
tribe( 'tec.featured_events' )->feature( $event->ID ); | |
} | |
} | |
} | |
add_action('after_setup_theme', 'ga_events_calendar_conditional_featured'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment