Created
August 6, 2023 17:42
-
-
Save cgdmohamed/e38f59420d58e399793cc765b16d7d67 to your computer and use it in GitHub Desktop.
Sort elementor archive posts snippet
This file contains 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 | |
/** | |
* Elementor archive posts sort | |
*/ | |
add_action( 'pre_get_posts', function ( $query ) { | |
// Only modify the query we want | |
if ( ! $query->is_main_query() || ! $query->is_archive() ) { | |
return; | |
} | |
// set posts per page | |
$query->set( 'posts_per_page', 3 ); | |
// set order by | |
$query->set( 'orderby', 'title' ); | |
// set order | |
$query->set( 'order', 'DESC' ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment