-
-
Save phirebase/6d5d5f535ce7b066721e694f636c8cdb to your computer and use it in GitHub Desktop.
[Combine "Divi - Filterable Blog Module" with the "Events Manager" plugin]
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 | |
// 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 | |
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 | |
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment