OpenAgenda / wordpress

Display customizable OpenAgenda calendars on your WordPress site
GNU General Public License v2.0
3 stars 2 forks source link

Add a filter to the main event loop #31

Closed eur2 closed 11 months ago

eur2 commented 1 year ago

Hi, I need to filter an openagenda into different sections (based on their region value) on one page. The idea is to modify the the main event loop in event-loop.php:

<?php
            while( $openagenda->have_events() ) : $openagenda->the_event();
                include openagenda_get_template( $template );
            endwhile; 
        ?>

I have created a filter into functions.php:

add_filter( 'openagenda_filters', 'my_custom_openagenda_filters', 10, 2 );
function my_custom_openagenda_filters( $filters, $agenda_uid ){
    if( 'your_agenda_uid' === $agenda_uid ){
        $filters['choice'][] = array(
            'field' => 'region', // Replace with the actual field name for region
            'value' => 'desired_region', // Replace with the desired region value
        );
    }
    return $filters;
}

I can't make it working. Any doc about this? Thank you in advance

vincedubroeucq commented 1 year ago

Hello, The filters should look like the URL you get when using the basic widget filters. For example, when filtering the agenda with the widgets you should get a url like this : https://example.com/agenda/my-agenda?region=toto

So the $filters variable in your hooked function should look like this :

$filters = array(
  'region' => 'toto'
);

Hope that helps !