Archived topic
Use Query loop to display the events calendar events on home page
3 replies · Started by Justin on August 8, 2022
Hey, I am using a media query to pull events onto my home page (created by The Events Cal plugin)
http://justinf27.sg-host.com/ - (scroll halfway down the page)
Is it possible to add the event date as a content source somehow?
Then I can display event dates as well as sort them in event date order (currently, it is set to show the event posted date).
Also - I am using Toolset Plugin to create a members directory. I read in a forum that you can actually create members directory using query loops in Generate Press in a similar way to how toolset works? Do you have any documentation on this? (I assume not as I can't find any - but thought I would ask). This would be an awesome addition to Generate Press :)
Thanks for your help.
Hi there,
at the moment the Query Loop only handles core post meta options, do you know how the plugin is storing the date you want to display ? If its in the Post Meta, then you can use the Content Source: Post Meta and enter your meta keys name.
Can you check with the plugin author and let us know.
Hey David - this worked well thank you.
Is there an easy way I can filter results by upcoming event date though?
When I filter by parent ID or Author - the order for these first few events is correct. But obviously this will only work if I create events in order that they come up (ie, if I added an event for today, that would show last on the list).
Perhaps I can't achieve event ordering with the Query loop, and I should just get the events cal pro plugin - just trying to keep the sight as lightweight as possible and achieve this through GP :)
Orderby Custom Field will be something we add in GB Pro in a future update.
But, we use the WP_Query function and we have the generateblocks_query_loop_args filter for adding custom parameters to the query.
Try this snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if (
! is_admin() &&
// if block has an advanced > additional CSS Class of: orderby-event-date
! empty( $attributes['className'] ) &&
strpos( $attributes['className'], 'orderby-event-date' ) !== false
) {
// pass meta_query parameter
$query_args[ 'meta_query' ] = array(
'meta_key' => 'your_event_date_meta_name',
'orderby' => 'meta_value_num',
'meta_type' => 'DATE',
'order' => 'DESC'
);
}
return $query_args;
} );
Note:
1. The orderby-event-date is a CSS Class that you need to add to the Query Loop block.
2. The your_event_date_meta_name needs to be replaced with the post meta field name which stores the date.