Show only first instance of recurring event in search results

Home Forums Calendar Products Events Calendar PRO Show only first instance of recurring event in search results

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #960956
    Gilles
    Participant

    I think I read that question a few times in the forum, so I thought I would post what I think is the solution. It seems to work for me. This is inspired by the code for the addGroupBy function in events-calendar-pro/lib/tribe-events-recurrence-meta.class.php.

    // Show only first instance of recurring events in search results
    add_filter( 'posts_groupby', 'my_posts_groupby', 10, 2);
    function my_posts_groupby ( $group_by, $query ) {
      if (is_admin() || !is_search())  return $group_by;
    
      global $wpdb;
      $group_by = " IF( {$wpdb->posts}.post_parent = 0, {$wpdb->posts}.ID, {$wpdb->posts}.post_parent )";
    
      return $group_by;
    }
    
    #960957
    Gilles
    Participant

    No assistance needed 🙂

    #960961
    Gilles
    Participant

    It’s probably better to replace is_search() by $query->is_search.

    #961079
    Brian
    Member

    I am glad to see you were able to figure it out.

    I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Show only first instance of recurring event in search results’ is closed to new replies.