In my Wordpress site I use plugin The Events Calendar (pro). There is a page with list of Events in backend. Link to this page looks like this: .php?post_type=tribe_events
So now I need to hook/filter into this list of events to modify it. My task is to initially show events of only one particular organizer.
Tried looking through exisiting hooks and filters of this plugin. But nothing seems to suit me. Also tried looking into plugin files, but couldn't find the one that is responsible for list of events in backend.
In my Wordpress site I use plugin The Events Calendar (pro). There is a page with list of Events in backend. Link to this page looks like this: https://example/wp-admin/edit.php?post_type=tribe_events
So now I need to hook/filter into this list of events to modify it. My task is to initially show events of only one particular organizer.
Tried looking through exisiting hooks and filters of this plugin. But nothing seems to suit me. Also tried looking into plugin files, but couldn't find the one that is responsible for list of events in backend.
Share Improve this question asked Aug 28, 2019 at 14:23 Kirill OzeritskiKirill Ozeritski 214 bronze badges 2- 2 Check with The Events Calendar's official support streams. – Pat J Commented Aug 28, 2019 at 14:36
- @PatJ I did. Nothing there. – Kirill Ozeritski Commented Aug 29, 2019 at 15:46
1 Answer
Reset to default 1Okay, I found the solution myself.
I used the WordPress hook parse_query
. This is the most precise thing I found.
And in this hook I check if it is backend and my user has his meta data called "organizer_id" which I added earlier. But it is only to get the needed organizer_id for filtering the list.
Here's the code:
add_filter( 'parse_query', 'ozz_filter_events_by_organizer' );
function ozz_filter_events_by_organizer( $query ) {
$current_user = wp_get_current_user();
$organizer_id = get_user_meta( $current_user->ID, 'organizer_id' );
if ( is_admin() and $query->query['post_type'] == 'tribe_events' and !empty( $organizer_id ) ) {
$qv = &$query->query_vars;
$qv['meta_query'][] = array(
'field' => '_EventOrganizerID',
'value' => $organizer_id
);
//echo '<pre>' . print_r( $qv, true ) . '</pre>';
}
}
So this filter-hook fires each time there is a query on the site. Not very handy but best I could find. So it allowed me to filter the query when it considered particularly the event list in the backend.