• Hello again,

    I want an archive page where all events are displayed. This is no problem, but now I need a loop the fetch only one event of each recurring event.

    Is there a way to include this
    echo EM_Events::output( array('groupby'=>'recurrence_id', 'groupby_orderby'=>'event_start_date,event_start_time'));

    into the loop?

    <?php if ( have_posts() ) : ?>
    
    <?php 
    while (have_posts()) : 
    	the_post();
    
    	/*
    	* Include the Post-Type-specific template for the content.
    	* If you want to override this in a child theme, then include a file
    	* called content-___.php (where ___ is the Post Type name) and that will be used instead.
    	*/
    	get_template_part( 'template-parts/content-archive', get_post_type() );
    					
    	endwhile;
    
    	the_posts_navigation();
    
    	else :
    
    	get_template_part( 'template-parts/content', 'none' );
    
    	endif;
    ?>
    • This topic was modified 6 years, 5 months ago by fabbaf.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    maybe this sample snippet can help and give you an 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');
    

    note: this snippet might not work out of the box but it might give you a good start

    Thread Starter fabbaf

    (@fabbaf)

    If been that far, but don’t know what to put into the array. Just starting to learn PHP. So I don’t know what

    'groupby_orderby' => 'event_start_date,event_start_time'

    would be in WordPress Query…

    This is not working (obviously):

    <?php
    	$args = array(
    		'post_type' => 'event',
    		'meta_query' => array('key'=>'recurrence_id', 'groupby_orderby'=>'event_start_date,event_start_time'),
    	);
    	$query = new WP_Query($args);
    ?>
    
    	<div class="archive-events-overview">
    		<div class="row">
    
    			<?php if ( $query->have_posts() ) : ?>
    
    				<?php
    				/* Start the Loop */
    				while ( $query->have_posts() ) :
    					$query->the_post('');
    
    					/*
    					* Include the Post-Type-specific template for the content.
    					* If you want to override this in a child theme, then include a file
    					* called content-___.php (where ___ is the Post Type name) and that will be used instead.
    					*/
    					get_template_part( 'template-parts/content-archive', get_post_type() );
    					
    				endwhile;
    
    				the_posts_navigation();
    
    			else :
    
    				get_template_part( 'template-parts/content', 'none' );
    
    			endif;
    			?>
    		</div>
    	</div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Recurring Events – show only one instance in the_loop’ is closed to new replies.