How To Show Divi Search Results In Alphabetical Order Tutorial By Pee Aye Creative

How To Show Divi Search Results In Alphabetical Order

In this tutorial I will show you how to display the Divi search results in the search results page in alphabetical order by title.
Categories: Divi PHP Tutorials

Join subscribers on our YouTube channel and enjoy other Divi video tutorials!

Add The PHP Code Snippet

This tutorial is easy, and only requires one step to add the PHP code that works behind the scenes to adjust the output of the search results. This simply involves copying and pasting the PHP code snippet below into your website. There are a number of locations to add this, and it will totally depend on your website and experience.

If you have a child theme, then you would add this snippet to the functions.php file of a Divi child theme. If you don’t already have one, you can download our free Divi child theme here.

If you want the easy way, then I will recommend installing the Code Snippets plugin. It is a great plugin that allows you to add snippets easily in the backend of your admin area. After activating, just go to Snippets>Add New, write a title, paste the snippet, and click the save and activate button. Here is how that will look:

screenshot showing code to disply Divi search results in alphabetical order


// show Divi search results in alphabetical order
function pa_alphabetical_search_results( $query ) {
	if( $query->is_search && !is_admin() ) {
		$query->set( 'orderby', 'title' );
		$query->set( 'order', 'ASC' );
add_filter( 'pre_get_posts','pa_alphabetical_search_results' );

Optional: Reverse The Order

If for some reason you want to show the items in the opposite order, you can edit the “ASC” in the code snippet. Simply replace the ASC with DESC the items will show from Z to A.

Last updated Oct 7, 2022 @ 11:15 pm


Each month we send out a roundup email newsletter with the latest tutorials, product updates, helpful resources, and any other industry or personal news. Occasionally we send an extra separate email here and there if we just can’t wait! So that’s what you will get if you subscribe, and you can always unsubscribe at any time if you just can’t take it anymore :)

Blog Post Optin

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative in the beautiful state of Pennsylvania. He loves helping small businesses, exploring outdoors, building websites with Divi, and teaching others.

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy


Submit a Comment

Your email address will not be published.

Recent Posts


Your Cart