Alter Query & pre_get_posts
-
hi,
I need to only display events to users who have the same ACF field in common with the event (not the others, never)
I use this code below which works very well but takes extremely long to process.
Is there a way to filter my events more efficiently? There are more than 2000 events and it can sometimes take more than 10 seconds to display the calendar.
Thank you guys !!
add_action( 'pre_get_posts', 'get_tribe_events_posts_exclude_cancelled' ); function get_tribe_events_posts_exclude_cancelled( $query ) { if ( ( in_array ( $query->get('post_type'), array('tribe_events') ) && ! is_admin() && ! is_front_page() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX && ! empty( $query->query['tribe_render_context'] ) && 'default' === $query->query['tribe_render_context'] && ! empty( $query->query['post_type'] ) && Tribe__Events__Main::POSTTYPE === $query->query['post_type'] )) { $bp = buddypress(); $user_id = $bp->loggedin_user->id; $user_caisse = get_field('caisse','user_'. $user_id); $metaquery[] = array( array ( 'relation' => 'AND', array( 'eventDisplay' => 'custom', 'start_date' => 'now', ), array( 'relation' => 'OR', /* Event Natio */ array( 'key' => '_caisse_key', 'value' => '', ), /* Ou Event Caisse */ array( 'relation' => 'AND', array( 'key' => '_caisse_key', 'value' => $user_caisse[0]->ID, 'compare' => 'LIKE' ), ), ), ) ); $query->set('meta_query', $metaquery); } }
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Alter Query & pre_get_posts’ is closed to new replies.