Changing the display order of Events

You can change the order in which events are displayed in archives using the filter. Add this code snippet to the function.php of your child theme.

if ( ! function_exists( 'shelly_taxonomy_query_args' ) ) {

	/**
	 * Change the order of theme legacy taxonomy queries
	 *
	 * @param $args
	 * @param string $taxonomy
	 *
	 * @return mixed
	 */
	function shelly_taxonomy_query_args( $args, string $taxonomy = '' ) {

		// Only change the query for the event category
		$query_taxonomy = $args['tax_query'][0]['taxonomy'] ?? '';
		if ( $query_taxonomy === $taxonomy ) {

			$post_type = $args['post_type'] ?? array();

			// Sort by event date
			if ( in_array( 'event', $post_type  ) ) {

				$args['meta_key'] = '_event_date';
				$args['meta_type'] = 'DATE';
				$args['orderby'] = 'meta_value';
				$args['order'] = 'DESC'; // ASC or DESC

			}

		}

		return $args;

	}

}
add_filter( 'shelly_taxonomy_query_args', 'shelly_taxonomy_query_args', 10, 2 );

This code snippet changes the arguments for WP Query. For more information on all available query arguments, see WordPress Codex.

In order for these modifications to work in Events Feed Elementor addons, you must disable the display Custom Order settings:

Was this article helpful to you?