Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Last active August 21, 2021 16:20
Show Gist options
  • Save askwpgirl/c5369f4c365564a1b78cc993611e8c7e to your computer and use it in GitHub Desktop.
Save askwpgirl/c5369f4c365564a1b78cc993611e8c7e to your computer and use it in GitHub Desktop.
Sort Elementor Posts Widget posts by ACF Date Field
<?php
// Don't copy the php start code above. Copy from below.
// This uses the Elementor Custom Query Documentation for extending a post query:
// https://developers.elementor.com/custom-query-filter/
// This sorts the Elementor posts widget by an ACF date field.
// Replace my_acf_date_field with your date field.
// Put event_filter in the Query ID field of the Elementor Post widget.
add_action( 'elementor/query/event_filter', function( $query ) {
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
$query->set('meta_key', 'my_acf_date_field');
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment