1

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.

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. Commented Aug 29, 2019 at 15:46

1 Answer 1

1

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.

3
  • Good on you for solving the problem! It is better to not take it personally, especially because third party plugins and code with restricted access, like pro versions, are off topic on WordPress Development. It's just part of the community guidelines, take a closer look at the help center to get familiar with them. Just a tip for future questions, being me more specific, optimally showing the code in question, increases the chances of getting an answer a lot, even if it's technically off topic. Commented Sep 10, 2019 at 17:34
  • You could target this via the pre_get_posts hook, it is a more common place to target WP_Query parameters. Additionally you could e.g. make use of get_current_screen() for the conditional, but more a matter of code aesthetics I guess. Commented Sep 10, 2019 at 17:45
  • @Nicolai thanks, I'll look into it, it seems more suitable indeed. Commented Sep 12, 2019 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.