Skip to content

Instantly share code, notes, and snippets.

@indikatordesign
Last active November 5, 2021 01:29
Show Gist options
  • Save indikatordesign/ae1080fed54357beb1c0edc1c375ab96 to your computer and use it in GitHub Desktop.
Save indikatordesign/ae1080fed54357beb1c0edc1c375ab96 to your computer and use it in GitHub Desktop.
[Combine "Divi - Filterable Blog Module" with the "Events Manager" plugin]
<?php
// Here you can see how to combine "Divi - Filterable Blog Module" with the free plugin "Events Manager": https://wordpress.org/plugins/events-manager/
// Just add these snippets to your themes functions.php and change them according to your needs.
// Combine Event Manager with "Divi – Filterable Blog Module" by changing the $query_args
// If you use it like this, the sorting starts with the current event and past events will be hidden automatically
add_filter( 'dfbm_query_args_output', function( $query_args )
{
if ( 'event' == $query_args['post_type'] )
{
$query_args['meta_query'] =
[
'relation' => 'AND',
'date' =>
[
'key' => '_event_start_date',
'value' => date( "Y-m-d" ),
'compare' => '>=',
'type' => 'DATE'
],
'time' =>
[
'key' => '_event_start_time',
],
];
$query_args['orderby'] =
[
'date' => 'ASC', // DESC
'time' => 'ASC', // DESC
];
} // end if
return $query_args;
});
// Show event date and time in "Divi – Filterable Blog Module" before the meta data
if ( false === strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) )
{
add_action( 'dfbm_post_meta_before', function( $post, $featured )
{
printf(
'<p class="post-meta event-time">From %1$s until %2$s</p>',
DateTime::createFromFormat('Y-m-d', get_post_meta( $post->ID, '_event_start_date', true ) )->format( 'd-m-Y' ),
DateTime::createFromFormat('Y-m-d', get_post_meta( $post->ID, '_event_end_date', true ) )->format( 'd-m-Y' )
// get_post_meta( $post->ID, '_event_start_time', true ) // get the start time
// get_post_meta( $post->ID, '_event_end_time', true ) // get the end time
);
}, 10, 2 );
} // end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment