• Resolved Tunn

    (@iuriem)


    Hi,

    Is there a way to exclude a country (or multiple countries) from an events list? I tried country="-US" but this not working. I know how to list events from a country, but how about the oposite?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    at the moment that is not available and might need custom coding on your part to make this work – https://wp-events-plugin.com/tutorials/creating-custom-event-search-attributes/

    Here’s how I did it:

    
    function ignore_country($conditions, $args){
        global $wpdb;
        $country = $args['country'][0];
        if($country && is_string($country) ){
            $sql = $wpdb->prepare("select event_id from web_em_events where location_id in (select location_id from web_em_locations where location_country = '%s')", $country);
            $conditions['country'] = "event_id NOT IN ($sql)";
        }
        return $conditions;
    }
    
    // The country in this case is a negative selector, as that's the point of the filter.
    $args = array('country' => $country, 'limit' => $num - $selected, 'orderby' => 'event_start_date, event_time');
    add_filter( 'em_events_build_sql_conditions', 'ignore_country',1,2);
    $events = EM_events::get($args);
    remove_filter( 'em_events_build_sql_conditions', 'ignore_country',1,2);
    

    Note that the country argument being passed in to the filter is an array, so you could exclude multiple countries if you wanted to.

    Thread Starter Tunn

    (@iuriem)

    @elqabbany

    Hi, Moustafa!

    Can you give an example of how to use your function? Generally speaking, I know how to call a function, but I can’t understand how to call yours to exclude a country (or multiple) :(.

    Regards,
    Iurie

    • This reply was modified 6 years, 11 months ago by Tunn.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude a country from events list’ is closed to new replies.