Support » Plugin: Events Manager » [Plugin: Events Manager] Combined WP_Query of events and locations

  • Resolved Chantal Coolsma


    A customer has a grid based homepage of both locations and events. They are shown based on post date (so newest location or event on top). I used WP_query, but now it shows past events too.

    Is there a simple way to filter those events? So event_end_date is history, don’t show the event.

    Any ideas?

Viewing 9 replies - 1 through 9 (of 9 total)
  • agelonwl


    easiest way is to use $EM_Events = EM_Events::get( array('scope'=>'future') );

    Advanced Usage

    That is only for events. I have a query_posts loop now, which shows 12 items on each page. This are the post types ‘post’, ‘event’ and ‘location’. However this could show events which are past. It just queries those post types and show them with the newest published on top.

    There must be a way to combine two queries:
    – events (future events)
    – locations

    Searched the web, found some examples but none of them work.

    Plugin Author Marcus


    NetWebLogic Support

    this is work in progress, but maybe the function build_wpquery_conditions in file classes/em-object.php will help you figure it out, as it builds a WP_Query array.

    Any news on this? I have a customer who wants to pay for it if you can give it some priority.

    I am not a die-hard coder, so I need a simple and easy way to accomplish this fast.

    Plugin Author Marcus


    NetWebLogic Support

    given we’re fully focused on working on the plugin with established priorities we can’t do that atm.

    otherwise you can try, a dev can probably figure out from what we’ve already done (e.g. in classes/em-posts-admin.php) to see what’s needed to build your specific queries.

    I tried. It’s not clear to me. I have a WP_Query now, but this shows also past events. This must be changed, otherwise my customer will stop using Events Manager.

    Plugin Author Marcus


    NetWebLogic Support

    I can’t do this for you, but the specific bit on WP_Query to edit is in the file above:

    }elseif ($scope == "future"){
    	$today = strtotime(date('Y-m-d', $time));
    	if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){
    		$query[] = array( 'key' => '_start_ts', 'value' => $today, 'compare' => '>=' );
    		$query[] = array( 'key' => '_end_ts', 'value' => $today, 'compare' => '>=' );

    which you then add like

    $wp_query->query_vars['meta_query'] = $query;

    I think I run in the same problem as that Infinite Scroll thingy. meta_query gives all or nothing.

    $args = array(
    		'post_type' => array( 'event','location','post' ),
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'posts_per_page' => 12,
    		'paged' => get_query_var('page'),
    		'scope' => 'future'

    As soon as I add meta_query, it even ignores locations. They don’t have a start or end date.

    Plugin Author Marcus


    NetWebLogic Support

    since locations don’t have dates, you can’t expect to search locations and events in the same way based on a date, that’s just how it is.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Events Manager] Combined WP_Query of events and locations’ is closed to new replies.