Last active
August 21, 2021 16:20
-
-
Save askwpgirl/c5369f4c365564a1b78cc993611e8c7e to your computer and use it in GitHub Desktop.
Sort Elementor Posts Widget posts by ACF Date Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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