• Resolved costino80

    (@costino80)


    Hello,

    Is there a way to show (under the event page for example) the upcoming events in the same category as the event ?

    A start could be this code maybe : {has_category_X}content{/has_category_X}
    or this : [events_list category="X"]

    In both case, I need to add the category id dynamically in the shortcode… or maybe in php ?

    Any idea ? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,
    Yes, you can add a conditional placeholder for this. In your case, you can implement your placeholder as described at https://wp-events-plugin.com/tutorials/creating-conditional-placeholders-for-events/

    Thread Starter costino80

    (@costino80)

    Hi @chathuripxl,

    Thanks for your answer. I did some digging and found a way to show my related events via PHP and shortcode.

    <?php 
    
    $category_id = do_shortcode('[event]#_CATEGORYID[/event]');
    $event_id = do_shortcode('[event]#_EVENTID[/event]');
    
    $EM_Events=EM_Events::get(array('scope'=>'future', 'limit'=>10, 'pagination'=>1, 'category'=>$category_id));
    
    $events_found=sizeof($EM_Events);
    
    if( $events_found > 0 ){
    	?>
    	<ul class="event-categories">
    		<?php foreach($EM_Events as $EM_Event): ?>
    			<li><?php echo $EM_Event->output("#_EVENTLINK - #_EVENTDATES"); ?></li>
    		<?php endforeach; ?>
    	</ul>
    	<?php	
    }else{
    	echo "No next event";
    }
    ?>

    I just can’t find a way to exclude the current event from the list. I have the id, but I can’t hide it from the list of related upcoming events. Maybe there is a parameter I haven’t found yet ?
    Any idea ?

    Thanks

    Hello,
    great you are almost there. Just need to check whether current event id is not equals to the event id in for loop.

    $category_id = do_shortcode('[event]#_CATEGORYID[/event]');
    $event_id = do_shortcode('[event]#_EVENTID[/event]');
    
    $EM_Events=EM_Events::get(array('scope'=>'future', 'limit'=>10, 'pagination'=>1, 'category'=>$category_id));
    
    $events_found=sizeof($EM_Events);
    if( $events_found > 0 ){
        ?>
        <ul class="event-categories">
            <?php foreach($EM_Events as $EM_Event):
                if($event_id != $EM_Event->id){?>
                <li><?php echo $EM_Event->output("#_EVENTLINK - #_EVENTDATES"); ?></li>
            <?php } endforeach; ?>
        </ul>
        <?php
    }else{
        echo "No next event";
    }
    Thread Starter costino80

    (@costino80)

    @chathuripxl

    Many thanks ! It works perfectly now. That was the last bit of code missing ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Related Upcoming Events ?’ is closed to new replies.