If you need to order your post alphabetically from A to Z or from Z to A in archive page. Then you need to hook to pre_get_post and modify the function parameter – $query object. To be precise, you need to set orderby and order properties. Do that using $object->set(k, v) method. Simple, add this code to your function.php file. In my case, I use products custom post type created in CPT UI plugin (but it works for every custom post type).

/**
 * Change the order of posts/pages/cpt in the Divi Blog module
 * @see https://www.youtube.com/watch?v=awg0gUfxC0c -> fix in comment by Wiktor Liszkiewicz
 */
function paChangeBlogModuleOrder($query)
{
    // $result = array_key_exists('products', $query->query); 
    // echo "<pre>";
    // var_dump($query->query);
    // echo "<br>";
    // echo "</pre>";
    if (array_key_exists('products', $query->query)) {
        // echo "custom sorting on!";
        $query->set('orderby', 'title');
        $query->set('order', 'ASC');
    }
}
add_action('pre_get_posts', 'paChangeBlogModuleOrder');

The debug of $query->query would like something liek that:

bool(true)
array(1) {
  ["products"]=>
  string(16) "design-materials"
}


https://www.peeayecreative.com/how-to-sort-divi-blog-module-posts-in-alphabetical-order/
https://www.elegantthemes.com/blog/tips-tricks/how-to-re-order-your-blog-posts-with-2-methods
https://wordpress.stackexchange.com/questions/64076/pre-get-posts-on-a-page

0
Would love your thoughts, please comment.x
()
x