Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1100755

    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

    #1101556

    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

    #1101660

    Hi,

    Awesome. Glad that you a solution. We’ll close the thread now.

    Have a nice day.

    Best regards,
    Ismael

    #1101662

    Hi,

    Awesome. Glad that you a solution. We’ll close the thread now.

    Have a nice day.

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.