How to modify list of events in backend (admin) of The Events Calendar plugin?

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.com/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.

Topic the-events-calendar Wordpress

Category Web


Okay, 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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.