[Solved] Build query to show future events (Events Manager)

Hi there,

I have to admit: I have very little knowledge about queries and I just started learning about it.

The problem: I have this query string post_type=event&scope=future&orderby=date-time&order=asc but only the post_type and order is recognised. The rest is ignored. When used in a looper it shows all the events instead of just the future events.

I have copied this string from the url https://my-website.com/wp-admin/edit.php?post_type=event&scope=future&orderby=date-time&order=asc which shows exactly the data I want.

What am I doing wrong here?

Many thanks!

Hi @Dagaloni,

Thank you for writing in, please try this query:

post_type%5B0%5D=event&post_status%5B0%5D=Future&order=ASC&orderby=date

Hope it helps,
Cheers!

Hi @friech, thank you very much! Unfortunately it doesn’t work. When I add %5B0%5D the query isn’t recognises anymore and it falls back to just regular posts.

Maybe I should describe what I would like to accomplish. I would like to use the data provided by Events Manager to make a custom design using loopers. The only problem is providing the column with the url of the event. I can retrieve the url by this shortcode [events_list limit="1" location="1"#_EVENTURL[/events_list] but I cannot use a shortcode in the url-field.

So I came up with another solution and that is to use the query string to pull the data. Now the problem is, I cannot only show the future events.

Is there a way I’m not exploring at the moment of something I’m overlooking?

Hello @Dagaloni,

To query the future events, you may need to check out this thread:

Kindly let us know how it goes.

Awesome! Thank you very much, I figured it out!

This is the code:

$meta_query[] = array(
	'key'     => '_event_start_date',
	'value'   => date('Y-m-d'),
	'compare' => '>=',
);

$query = array(
	'post_type' => 'event',
	'posts_per_page' => '4',
	'post_status'  =>  'publish',
	'meta_key' => '_event_start_date',
	'orderby' => 'meta_value',
	'order' => 'ASC',
	'offset' => '0',
	'meta_query' => $meta_query
);

echo( http_build_query( $query ) );

And this is the query string. Please note that you have to replace the date (e.g. 2021-10-05) in the provided string with {{dc:global:date format="Y-m-d"}}:

post_type=event&posts_per_page=4&post_status=publish&meta_key=_event_start_date&orderby=meta_value&order=ASC&offset=0&meta_query%5B0%5D%5Bkey%5D=_event_start_date&meta_query%5B0%5D%5Bvalue%5D={{dc:global:date format="Y-m-d"}}&meta_query%5B0%5D%5Bcompare%5D=%3E%3D
1 Like

You are most welcome, @Dagaloni!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.