Skip to main content

How to Change the Default Sorting Order of Posts in the Blog Module

Learn how to change the post sorting order using the Blog module to ensure the display order that best suits your content strategy

Updated over a week ago

Customizing the sorting order of your blog posts can enhance user experience and help highlight your most important content.

In this article, we will guide you through the process of changing the default sorting order of posts in Divi's Blog Module.

There are two methods we can use:

  • Method 1: Use a PHP snippet (without a child theme) - recommended

  • Method 2: Use a Child Theme

Method 1: Use a PHP snippet (without a child theme) - recommended

Change the Post ordering for all Blog modules

  1. Go to WordPress Dashboard → Plugins and install the Code Snippets plugin.

  2. Create a new PHP Snippet.

  3. Give the snippet a title and paste in the following PHP code:

    function custom_blog_order($query, $args) {
    $query->query_vars['orderby'] = 'title';
    $query->query_vars['order'] = 'desc';
    $query = new WP_Query($query->query_vars);

    return $query;
    }
    add_filter('et_builder_blog_query', 'custom_blog_order', 10, 2);

  4. Save and activate the snippet.

Note: The above PHP snippet will change the post order based on their titles, with the order descending. This will apply to all Blog modules on your website.

Change the Post ordering only on specific Blog modules

If you have multiple instances of the Blog module on your website, but you want to change the default post order only for specific Blog modules, follow the steps below:

  1. Go to WordPress Dashboard → Plugins and install the Code Snippets plugin.

  2. Create a new PHP Snippet.

  3. Give the snippet a title and paste in the following PHP code:

    function custom_blog_order_class($query, $args) {
    if (isset($args['module_id']) && $args['module_id'] === 'dt-post-order-by-title') {
    $query->query_vars['orderby'] = 'title';
    $query->query_vars['order'] = 'ASC';
    $query = new WP_Query($query->query_vars);
    }

    return $query;
    }
    add_filter('et_builder_blog_query', 'custom_blog_order_class', 10, 2);

  4. Edit the Blog module(s) for which you want to change the default post ordering

  5. Go to the Advanced Tab → CSS ID & Classes → CSS Class

  6. Type in dt-post-order-by-title

Note: Only the Blog modules with the CSS class dt-post-order-by-title will have their posts ordered by title in Ascending order.

In both cases, you can change the values for:

  • $query->query_vars['orderby']

  • and $query->query_vars['order']

For more information on ordering, please visit the WordPress Developer Documentation page.


Method 2: Use a Child Theme

Note: Before continuing with this article, ensure the following:

  1. Go to Appearance → Theme File Editor

  2. Open the Blog.php file from your Child theme folder

  3. Search this piece of PHP code:

    $args['cat'] = implode( ',', self::filter_include_categories( $include_categories ) );
    $args['paged'] = $et_paged;

    Divi - Customize the Blog Module code and change the default display order

  4. Add this PHP code right after it:

    $args['orderby'] = 'title';
    $args['order'] = 'asc';

    Divi - Customize the Blog Module code - Change the default display order

  5. Save your changes.

The Posts will not be displayed in Ascending order based on their titles.

Did this answer your question?