Skip to content

Instantly share code, notes, and snippets.

@elimn
Last active April 19, 2022 13:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save elimn/d034dfddb9be206d9cc1 to your computer and use it in GitHub Desktop.
Save elimn/d034dfddb9be206d9cc1 to your computer and use it in GitHub Desktop.
MT | TEC | Set the default date for views like List and Month
<?php
/*
* Set the default date for views like List and Month
* Modify the $date variable below to set your date
*/
function tribe_set_default_date( $wp_query ) {
// Only run on main event queries
if ( ! tribe_is_event_query() || ! $wp_query->is_main_query() || $wp_query->get( 'eventDate' ) != '') return;
// Set this to the date you want shown, in YYYY-MM-DD format
$date = '2000-01-01';
// Select which TEC views you want this to apply to by uncommenting them
if (
tribe_is_list_view()
// || tribe_is_map()
// || tribe_is_photo()
// || tribe_is_month()
// || tribe_is_week()
// || tribe_is_day()
) {
$wp_query->set( 'eventDate', $date );
}
}
if ( function_exists('tribe_is_event_query') ) {
add_action( 'parse_query', 'tribe_set_default_date', 100);
}
/*
* Sets the date search value to never be blank
*/
function tribe_bar_set_date_val( $filters ) {
global $wp_query;
$new_val = 'value="' . esc_attr( $wp_query->get( 'eventDate' ) ) . '"';
$filters['tribe-bar-date']['html'] = preg_replace( '/value="[^"]*"/', $new_val, $filters['tribe-bar-date']['html'] );
return $filters;
}
add_filter( 'tribe-events-bar-filters', 'tribe_bar_set_date_val', 100, 1 );
@KooBa777
Copy link

@calebfergie Thanks a lot for the reply. What else should be done after pasting the code to function.php? It doesn't seem to work for me at the moment.

@calebfergie
Copy link

@KooBa777 everyones wordpress is a little different. Here’s all i know for sure:

  • make sure you hit save/update at the bottom of the sceeen
  • Confirm you are changing the functions.php file in your ACTIVE theme - change this in the top right corner with the dropdown menu.

Let me know how it goes!

@aradzhioni
Copy link

Hi there, thanks so much for this.

Our events page is almost at where we need - check it out here- I took a look at the Themer's Guide but can't seem to figure out how to:

  1. Change the title from "Upcoming Events" to something else (e.g. "BlockApps Events")
  2. Change the order of the events to most-recent first (is currently least-recent first)

Could you tell us how to do so? I am comfortable manipulating PHP but don't know really how to code for it. We also use Avada if that is relevant to the solution.

As I can see your page is perfect now.

I tried your code, but I can only get all the events on one page. No reverse pagination, No separation between past and upcoming events.
Can you please tell me did you made any changes in the code that you have sent here, or maybe some other things you did to do it the way to shows now?

Thank you in advance!

@calebfergie
Copy link

As I can see your page is perfect now.

I tried your code, but I can only get all the events on one page. No reverse pagination, No separation between past and upcoming events. Can you please tell me did you made any changes in the code that you have sent here, or maybe some other things you did to do it the way to shows now?

Thank you in advance!

hi @aradzhioni - I'm sorry, but I don't work at BlockApps anymore and no longer have access to the wordpress 😞

Good luck with it!

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