How to only show single, future instance of recurring event in WordPress search?

Home Forums Calendar Products Events Calendar PRO How to only show single, future instance of recurring event in WordPress search?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1028807
    juvecreative
    Participant

    I’m trying modify the site search (e.g http://www.mysite.com/?s=test) so that it returns only the first upcoming instance of a recurring event. I’ve searched high and low, both on these forums and on Google, and all I found was this: https://theeventscalendar.com/support/forums/topic/show-only-first-instance-of-recurring-event-in-search-results/

    // 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;
    }

    I went ahead and added the above to my functions.php, and the search now returns a single instance. However, it is not limited to current/future events, and will return past events too, which obviously isn’t desired.

    How would I go about limiting the search to only show the first instance out of the current/future list?

    Thanks!

    #1029691
    Barry
    Member

    Hi JuveCreative,

    Interesting request!

    Though working through customizations like this one are a little bit beyond the level of support we typically provide here on the forums, it does sound like this would make for a great enhancement.

    In terms of removing past/expired events from the search results, it looks like others have already requested this and I’d encourage you to add your support.

    On the other hand, I don’t however see any existing requests to respect the show only the first instance of each recurring event within search queries – but you could certainly create one.

    Posting feature requests in this way is a great means of getting ideas in front of us and it allows other users to add their support – giving a great sense of just how much demand there might be ๐Ÿ™‚

    #1039303
    simpleconnections
    Participant

    I ended up throwing a solution to this together, it’s not a short bit of code though. It uses a Tribe function Tribe__Events__Pro__Recurrence_Meta::get_recurrence_for_event($postId) that seems to have a php warning no matter what event post gets passed to it. It’s not thoroughly bug tested ATM either, so if you end up using please let me know.

    Thanks for the filter btw, Juvecreative – came in useful to group the recurrences.

    I’m not really sure what the best way to share the solution is, or if the Tribe people want the code so they can integrate the feature in?

    #1039603
    Barry
    Member

    Hi @simpleconnections – a Gist URL is a great way to share code. Just pop the URL on a line of its own in your reply and the code will be embedded here in the forums (or you could of course provide the URL to other similar services likes Pastebin, though we don’t support automatic embedding for those).

    #1039789
    simpleconnections
    Participant

    Ok. The code modifications I’ve made actually also hides old events (has a little note and a javascript show/hide for the old events), so if you don’t want that you’ll have to separate that yourself. That being said, it think it’s a good feature and my client had a lot of complaints from that not being in place.

    Edit: that gist embed is vicious on the eyes, and it doesn’t collapse, is there a way to make a gist embed look a little nicer?

    My modified search.php:
    https://gist.github.com/brettins/2193fb7c7a5ee3f92276

    The functions I added to functions.php:
    https://gist.github.com/brettins/efffea2ca0faa8b9c183

    #1039961
    Barry
    Member

    Thanks for sharing!

    Edit: that gist embed is vicious on the eyes, and it doesnโ€™t collapse, is there a way to make a gist embed look a little nicer?

    Some of our theme’s formatting rules are ‘leaking’ into the embedded gists – the zebra striping effect in particular is a little strong – and I believe we have a plan to address that, albeit it’s a fairly low priority.

    However, we will address it (and making them collapsible isn’t a bad idea at all – I’ll be sure to log that) ๐Ÿ™‚

    #1076155
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘How to only show single, future instance of recurring event in WordPress search?’ is closed to new replies.