Tagged: blog posts, sort order, the events calendar
Hello, I am using the following code on my site to reverse the sort order for a Blog Posts element used to display The Events Calendar events:
add_filter('avia_post_slide_query','avia_modify_blog_post_query');
function avia_modify_blog_post_query( $query)
{
$query['orderby'] = 'date';
$query['order'] = 'ASC';
return $query;
}
The problem is that this reverses the order for all Blog Post elements. Is there a way to modify this so that it acts only on event posts, and not all blog posts?
(Also as a point of feedback, it would be great if the Blog Posts element received an option to control sort order, similar to Masonry and other elements.)
Thanks in advance,
Gary
Update:
I discovered the solution and am posting it here in case anyone else has the same requirement. It turns out that it is possible to check the taxonomy of the current query, making it easy to scope the function to affect only events:
add_filter('avia_post_slide_query','avia_modify_blog_post_query');
function avia_modify_blog_post_query( $query)
{
$tax = $query['tax_query'][0];
if ($tax['taxonomy'] == 'tribe_events_cat') {
$query['orderby'] = 'date';
$query['order'] = 'ASC';
}
return $query;
}
Cheers,
Gary
Hi,
Awesome. Glad that you a solution. We’ll close the thread now.
Have a nice day.
Best regards,
Ismael