Skip to content

Instantly share code, notes, and snippets.

@cgdmohamed
Created August 6, 2023 17:42
Show Gist options
  • Save cgdmohamed/e38f59420d58e399793cc765b16d7d67 to your computer and use it in GitHub Desktop.
Save cgdmohamed/e38f59420d58e399793cc765b16d7d67 to your computer and use it in GitHub Desktop.
Sort elementor archive posts snippet
<?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