Skip to content
WhatsApp ZahidContactPricing

Code snippet

Elementor Archive Posts with Advanced Sorting

Elementor Archive Posts with Advanced Sorting Code Snippets by Zahid Aramai, Freelance Web Designer Malaysia

PHP · functions.php or a code snippets plugin
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' );
} );

Let's get in touch

Need this built into your website?

If you would rather not touch code, I can add it for you as part of a Website Care Plan or a one-off job. Ask on WhatsApp.

Reply within one working day

Message Zahid directly

WhatsApp
+60 11-5197 8879
Hours
Monday to Saturday 10 am to 6 pm · Sunday closed
Based in
Kuala Lumpur, Malaysia
WhatsApp Zahid