Support

Home Forums Event Espresso Premium Offset attribute for custom query?

Offset attribute for custom query?

Posted: December 12, 2017 at 9:00 pm


salda

December 12, 2017 at 9:00 pm

Hi there,

On a couple of pages (such as homepage) we have events showing in custom places. Without being able to show you (as the site’s still in local development), I’ll try explain the layout; 3 columns, 2 rows.
Position 1: latest post
Position 2: latest post in specific category
Position 3: the first upcoming event from EE4
Full width feature panel.
Position 4: the latest post offset by 1
Position 5: latest post in specific category offset by 1
Position 6: the second upcoming event from EE4

I can get Position 3 without any trouble using this:

// third - upcoming event
$event_atts = array(
	'title' => NULL,
	'limit' => 1,
	'css_class' => NULL,
	'show_expired' => FALSE,
	'month' => NULL,
	'category_slug' => NULL,
	'order_by' => 'start_date',
	'sort' => 'ASC'
);
global $wp_query;
$wp_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $event_atts );
	if (have_posts()) : while (have_posts()) : the_post();
        get_template_part( 'part_list-childposts' );
	endwhile;
    endif;
wp_reset_query();
wp_reset_postdata();

When I get to Position 6, I’m having trouble returning the second soonest upcoming event. I’m wanting to use something like:
'offset' => 1
As I do in the custom queries for position 4 and 5, but I’m having no luck tracking down a list of attributes that I can use with EventListQuery.

Thanks in advance, please let me know if you need any more clarification.

Cheers,
Min


Josh

  • Support Staff

December 14, 2017 at 11:27 am

Hi Min,

EventListQuery actually extends WP_Query and offset is already defined ahead of time. You’ll see what I mean here:

https://github.com/eventespresso/event-espresso-core/blob/master/core/domain/services/wp_queries/EventListQuery.php#L170

You can add this to your Position 6 code right after the
global $wp_query;:

set_query_var('paged', 2);

and that will change the offset value to 1.


salda

December 17, 2017 at 2:21 am

Aha, perfect! Thank you heaps, that makes sense.

The support post ‘Offset attribute for custom query?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso