• Resolved guillermovargasquisoboni

    (@guillermovargasquisoboni)


    I’m trying to create a double query and a double loop in a website using the plugin event organiser in order to separate current events and future events. The code I’m using is not working, because I get two times the same information (present events). I cannot figure out what I’m doing bad. Someone there can help me?

    This is the code I’m using :

    <?php   $presentevents = eo_get_events(array(
                'events_start_before'=>'today',
                'events_end_after'=>'today',
                'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
            ));
    
        if( $presentevents ){
                echo '<h2>', 'Eventos en curso', '</h2>';
                foreach( $presentevents as $event1 ){
                    printf("<article><a href='%s' >%s</a> from %s to %s </article>",
                        get_the_permalink($event1->ID),
                        get_the_title($event1->ID),
                        eo_get_the_start('jS F Y', $event1->ID,null,$event1->occurrence_id),
                        eo_get_the_end('jS F Y', $event1->ID,null,$event1->occurrence_id)
                    );
                }
    
            }else{
            echo 'No hay eventos en curso';
            }
        wp_reset_postdata();
        ?>
        <?php   $futurevents = eo_get_events(array(
                'events_start_after'=>'tomorrow',
                'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
            ));
    
        if( $futurevents ){
                echo '<h2>', 'Eventos futuros', '</h2>';
    
                foreach( $futurevents as $event2 ){
                    printf("<article><a href='%s' >%s</a> from %s to %s </article>",
                        get_the_permalink($event2->ID),
                        get_the_title($event2->ID),
                        eo_get_the_start('jS F Y', $event2->ID,null,$event2->occurrence_id),
                        eo_get_the_end('jS F Y', $event2->ID,null,$event2->occurrence_id)
                    );
                }
    
                }else{
                echo 'No hay eventos futuros';
                }
        wp_reset_postdata();
        ?>

    https://wordpress.org/plugins/event-organiser/

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

    (@guillermovargasquisoboni)

    I found the solution : I was making a very simple mistake! The arguments in the query has to be in singular.
    This is the new piece of code to use in the first query :

    <?php   $presentevents = eo_get_events(array(
                'event_start_before'=>'today',
                'event_end_after'=>'today',
                'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
            ));

    and this is the one for the second query :

    <?php   $futurevents = eo_get_events(array(
                'event_start_after'=>'tomorrow',
                'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
            ));

    Thread Starter guillermovargasquisoboni

    (@guillermovargasquisoboni)

    And here is the entire code for the template (if you are interested on)…

    <?php
    /**
     * This template is a Front Page with two loops for events (present and future events) and one loop for posts (recent news)
     * The template is calling elements from the plugin event organiser (http://wp-event-organiser.com/) in a twentyfifteen child theme
     */
    
    get_header(); ?>
    
    <div id="primary" class="content-area">
    	<main id="main" class="site-main" role="main">
    
    	<header class="entry-header">
    			<h1 class="entry-title">Agenda</h1>
    	</header><!-- .entry-header -->
    
    	<div class="entry-content">
    		<?php	$presentevents = eo_get_events(array(
         			'event_start_before'=>'today',
         			'event_end_after'=>'today',
         			'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
      			));
    
    		if( $presentevents ){
        			echo '<h2>', 'Eventos en curso', '</h2>';
        			foreach( $presentevents as $event1 ){
          				printf("<article><a href='%s' >%s</a> from %s to %s </article>",
            				get_the_permalink($event1->ID),
            				get_the_title($event1->ID),
            				eo_get_the_start('jS F Y', $event1->ID,null,$event1->occurrence_id),
            				eo_get_the_end('jS F Y', $event1->ID,null,$event1->occurrence_id)
          				);
         			}
    
    			}else{
    
    			}
    		wp_reset_postdata();
    		?>
    		<?php	$futurevents = eo_get_events(array(
         			'event_start_after'=>'tomorrow',
         			'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
      			));
    
    		if( $futurevents ){
        			echo '<h2>', 'Eventos futuros', '</h2>';
    
        			foreach( $futurevents as $event2 ){
          				printf("<article><a href='%s' >%s</a> from %s to %s </article>",
            				get_the_permalink($event2->ID),
            				get_the_title($event2->ID),
            				eo_get_the_start('jS F Y', $event2->ID,null,$event2->occurrence_id),
            				eo_get_the_end('jS F Y', $event2->ID,null,$event2->occurrence_id)
          				);
         			}
    
    				}else{
    
    				}
    		wp_reset_postdata();
    		?>
    
    		<?php if ( have_posts() ) : ?>
    			<h2>Últimas noticias</h2>
    			<?php if ( is_home() && ! is_front_page() ) : ?>
    				<header>
    					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    				</header>
    			<?php endif; ?>
    
    			<?php
    			// Start the loop.
    			while ( have_posts() ) : the_post();
    
    				/*
    				 * Include the Post-Format-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 Format name) and that will be used instead.
    				 */
    				the_title();
    
    			// End the loop.
    			endwhile;
    
    		// If no content, include the "No posts found" template.
    		else :
    
    		endif;
    		?>
    
    </div><!-- .entry-content -->
    </main><!-- .site-main -->
    </div><!-- .content-area -->
    
    <?php get_footer(); ?>

    Thread Starter guillermovargasquisoboni

    (@guillermovargasquisoboni)

    Topic resolved!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Troubles Creating a Double Loop in Own Template’ is closed to new replies.