David

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: Only show next event in search results #1132700
    David
    Participant

    Well, after all my mucking about, the code posted in this thread appears to work.

    in reply to: Only show next event in search results #1132695
    David
    Participant

    Thanks for your follow-up Josh.

    I’ve modified my search loop to the below code. Note that I’ve removed the templating for brevity’s sake, but it does successfully identify recurring events.

    <?php if ( get_post_type() == 'tribe_events' && tribe_is_recurring_event() == 1 ) : ?>
        <!--Recurring Event-->
    <?php else : ?>
        <!--Everything Except Recurring Events-->
    <?php endif; ?>

    Any tips on how I might make the final tweak to only pull the next recurring event?

    Cheers.

    in reply to: Only show next event in search results #1131337
    David
    Participant

    Okay, after some more investigation i’ve updated my code:

    add_filter( 'pre_get_posts', 'hide_recurring_event_search' );
     
    function hide_recurring_event_search( $query ) {
        if ( ! is_admin() && $query->is_main_query() ) {
            if ( $query->is_search ) {
              
              $query->set( 'meta_key', '_EventEndDate' );
              $query->set( 'meta_value', date('m-d-Y') . ' 00:00:00' );
              $query->set( 'meta_compare', '>=' );
    
              $query->set( 'tribeHideRecurrence', true );
              $query->tribe_is_multi_posttype = true;
            }
        }
    }

    However, my search results are now purely events, rather than including posts/pages/events and other custom post types (which I need to do.)

    Any thoughts on how I could fix the code so searches include everything?

    in reply to: Only show next event in search results #1130752
    David
    Participant

    Couple of minor issues with the code- appears to be getting close though.

    First: I only get one search result per page.
    Second: Searches list both the parent and next child events.

    Site this is on is now semi-public, so I can point you at http://linkup.org.nz/?s=food and you’ll see what I mean.

    add_action( 'pre_get_posts', 'hide_recurring_event_search' );
    
    function hide_recurring_event_search( $query ) {
      if ( !is_admin() && $query->is_main_query() ) {
        if ($query->is_search) {
          $query->set( 'post_parent', '0' );
          $query->set( 'meta_key', '_EventStartDate' );
          $query->set( 'meta_value', date('Y-m-d') . ' 00:00:00' );
          $query->set( 'meta_compare', '>=' );
          $query->set( 'posts_per_page', 1 );
        }
      }
    }
    • This reply was modified 9 years, 11 months ago by David. Reason: More detail
Viewing 4 posts - 1 through 4 (of 4 total)