Code by Day | Explore By Weekend

How To Sort Divi Blog Module Posts In Alphabetical Order Tutorial by Pee Aye Creative

How To Sort Divi Blog Module Posts In Alphabetical Order

Our tutorial today will show you how to sort blog posts or other custom posts types in the Divi Blog module in alphabetical order.

To change the default order of the Divi Blog module items, we need to override the existing code. We can do this by adding some PHP code to your Divi website.

Where To Place The Code

If you are using our free Divi child theme or any other child theme, place this snippet into the functions.php file. Otherwise, there may be some PHP code snippet plugins that you can use that do a similar function.

//change the order of posts/pages/cpt in the Divi Blog module

add_action('pre_get_posts', 'pa_change_blog_module_order');

function pa_change_blog_module_order($query) {
$pac = get_query_var( 'post_type' );
if ( 'post' == $pac )
{

$query->set('orderby', 'title');
$query->set('order', 'ASC');
}
}

Once you paste the code into your functions.php file, make sure to save the file and then go look at the results. Your Divi Blog module will show the items in alphabetical order from A to Z.

Other Post Types

The Divi Blog module has the option to show any post type. This means you can display a grid of pages, posts, projects, products, events, or any other custom post type that you have on your site.

In order to use anything other than the default blog posts, you will need to make a small edit to the snippet. All you have to do is change the “post” to match the post type that you are using. For example, for pages it would simply be “page” or for projects it would simply be “projects.”

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 the items will show from Z to A.

5
Last updated Feb 23, 2021 @ 9:52 am

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative Co in the beautiful state of Pennsylvania. He loves helping small businesses, exploring, building websites with Divi, and teaching others.
Divi Adventure Club Product And Course Membership by Pee Aye Creative

Become A Member!

Gain access to everything we offer!

Learn More

Leave A Response!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Shop Our Divi Products

Plugins • Courses • Templates

Visit The Shop

Divi Adventure Club Product And Course Membership by Pee Aye Creative

Become A Member!

Gain access to everything we offer!

Learn More

Divi Tutorials On YouTube

Join over 5,200 others and subscribe to our helpful Divi videos!

Visit Our Channel

Recent Posts

Pin It on Pinterest

0

Your Cart