• I need to create a custom event loop. I used to use EM_Events::get($args), but now it doesn’t seem to work anymore, I don’t know if it’s my mistake or something else. In particular I would need an event loop that has a ‘scope’ => ‘future’ and that contains a certain event tag. I could do this with WP_Query but I don’t know how to filter future events. I didn’t find much information in the documentation so I wanted to know if with the new versions of the plugin there is a built-in way to create custom event loops or if the $args available for EM_Events::get have changed.
    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • To get WP_Query to show only future events add the following to the WP_Query $args array:

    $current_date = current_time('Y-m-d');
    $args['meta_query'] = [
            'key' => '_event_start_date',
            'value' => $current_date,
            'compare' => '>=',
    ];
    $args['meta_type'] = 'DATE';
    $args['orderby'] = 'meta_value;

    Can you show the $args you pass to EM_Events::get($args) that is no longer working?

    The following worked:

        $events = EM_Events::get( [ 'owner' => 1 ] );
        foreach( $events as $event ){
           $ret .= $event->output( '#_EVENTNAME' ) . '<br />';
        }
        echo $ret;
    Thread Starter wordsar2793

    (@wordsar2793)

    Thanks, this query works.
    While the use you suggested with EM_Events::get still doesn’t work for me.
    The $args I passed previously are as follows:

    $args = array(
        'post_type' => 'event',
        'post_status' => 'publish',
        'suppress_filters' => true,
        'tag' => $tag->slug,
        'posts_per_page' => -1,
        'order' => 'ASC',
        'orderby' => 'event_start_date,event_end_date',
        'scope' => 'future',
    );

    These $args with older versions of the plugin worked.

    I tried the following and it worked for me:

        $args = array(
           'post_type' => 'event',
           'post_status' => 'publish',
           'suppress_filters' => true,
           'tag' => 'charity',
           'posts_per_page' => -1,
           'order' => 'ASC',
           'orderby' => 'event_start_date,event_end_date',
           'scope' => 'future',
        );
        $events = EM_Events::get( $args );
        foreach( $events as $event ){
           $ret .= $event->output( '#_EVENTNAME' ) . '<br />';
        }
        echo $ret;
    Thread Starter wordsar2793

    (@wordsar2793)

    In fact it works in general, but in my specific case I also have the WPML translation plugin on my site. In this case I have both the events in the original language and those translated into the secondary language.Translated events are simply duplicates.

    When the language is changed it shows the posts with the relevant language. It works well with all types of posts with WP_Query while with EM_Events::get it only shows me the events in the secondary language, in the main language no events come out.

    What could I have done wrong? The arguments are the same

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom events loop’ is closed to new replies.