• Resolved Jennyfer37

    (@jennyfer37)


    Hi,
    I’ve installed Relevanssi to help with my site search. It searches events fine but is bringing up past events too. Any idea how i can adjust the site search so it only shows events with a “future” scope?

    Thanks
    Jen

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Jennyfer37

    (@jennyfer37)

    Just to add, the Relevanssi forum suggested this:

    Create a relevanssi_do_not_index filter function that removes the past events from the index.

    add_filter( ‘relevanssi_do_not_index’, ‘rlv_remove_past_events’, 10, 2 );
    function rlv_remove_past_events( $block, $post_id ) {
    $post_type = relevanssi_get_post_type( $post_id );
    if ( ‘event’ === $post_type ) {
    // get event date somehow, and if it’s already past:
    $block = true;
    }
    return $block;
    }

    Can anyone advise with how to get the date and if it’s already in the past? Would using scope=’past’ work? No clue with php at all…

    Thanks
    Jen

    Thread Starter Jennyfer37

    (@jennyfer37)

    Just to add, the Relevanssi forum suggested this:

    Create a relevanssi_do_not_index filter function that removes the past events from the index.

    add_filter( ‘relevanssi_do_not_index’, ‘rlv_remove_past_events’, 10, 2 );
    function rlv_remove_past_events( $block, $post_id ) {
    $post_type = relevanssi_get_post_type( $post_id );
    if ( ‘event’ === $post_type ) {
    // get event date somehow, and if it’s already past:
    $block = true;
    }
    return $block;
    }

    Can anyone advise with how to get the date and if it’s already in the past? Would using scope=’past’ work? No clue with php at all…

    Thanks
    Jen

    Plugin Support angelo_nwl

    (@angelo_nwl)

    sorry but not familiar with your code however maybe this can give you additional info or idea

    
    function my_em_wp_query(){
    	$args = array(
    		'post_type' => 'event',
    		'posts_per_page' => 100,
    		'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_key' => '_start_ts',
    		'meta_value' => current_time('timestamp'),
    		'meta_value_num' => current_time('timestamp'),
    		'meta_compare' => '>='
    	);
    
    	// The Query
    	$query = new WP_Query( $args );
    
    	// The Loop
    	while($query->have_posts()):
    	$query->next_post();
    	$id = $query->post->ID;
    	echo '<li>';
    	echo get_the_title($id);
    	echo ' - '. get_post_meta($id, '_event_start_date', true);
    	echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    }
    add_shortcode('em_wp_query','my_em_wp_query');
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude past events from site search’ is closed to new replies.