• Resolved Robin Hislop

    (@tramuntana)


    I am using the WordPress get_posts function to return a list of events for display in a custom template:

    $args = array(
    	'posts_per_page' => get_option( 'posts_per_page' ),
    	'post_type' => 'tribe_events',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'tribe_events_cat',
    			'field' => 'slug',
    			'terms' => 'webinars',
    			'operator' => 'IN'
    		)
    	)
    );
    $events = get_posts( $args );

    However, this only returns upcoming events. I wish to show all events, including past events. It appears that get_posts is being filtered. How do I disable this filter?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Barry

    (@barryhughes-1)

    Hi @tramuntana,

    I’m afraid that helping with custom code is beyond what we can generally offer here in the free support forums, but I’d encourage you to review the following resource:

    theeventscalendar.com/knowledgebase/using-tribe_get_events

    I hope that helps!

    Thread Starter Robin Hislop

    (@tramuntana)

    Thanks for the reply Barry, but I’d already read that documentation and the tribe_get_events function doesn’t allow to filter by category, which is what I need.

    The get_posts query I have written should return all posts with post_type “tribe_events” regardless of EventStartDate, so something must be filtering the output, I suspect there is a pre_get_posts hook somewhere in the plugin code.

    Thread Starter Robin Hislop

    (@tramuntana)

    OK, on further investigation, tribe_get_events does do the trick as it is effectively a wrapper for get_posts so I can pass my tax_query into it.

    This is what I ended up using:

    $args = array(
    	'posts_per_page' => get_option( 'posts_per_page' ),
    	'order_by' => 'post_date',
    	'order' => 'DESC',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'tribe_events_cat',
    			'field' => 'slug',
    			'terms' => $category,
    			'operator' => 'IN'
    		)
    	),
    	'eventDisplay' => 'custom'
    );
    $events = tribe_get_events( $args );

    Thanks for the pointer Barry.

    Barry

    (@barryhughes-1)

    Glad you’re all sorted and thanks for sharing your final solution ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_posts only returns upcoming events’ is closed to new replies.