How to order posts by meta value in WordPress?

I have a common meta key in all my posts. Now I want to order them DESC by meta value. How do I do that?

You can use pre_get_posts to order your posts.

add_action( 'pre_get_posts', 'custom_post_order' );
function custom_post_order( $query ) {
    if ( $query->is_main_query() && $query->is_post_type( 'post' ) ) {
        // Set The Meta Key
        $query->set( 'meta_key', 'custom_meta_key' );
        // Sort by a meta value num
        $query->set( 'orderby', 'meta_value_num' );
        $query->set( 'order', 'DESC' );

If your meta value is not a number then you can just use meta_value instead of meta_value_num.

$query->set( 'orderby', 'meta_value' );

You can do the same with wp_query.

$args = array( 
    'post_type'    => 'post',
    'meta_key'     => 'custom_meta_key',
    'orderby'      => 'meta_value_num',
    'order'        => 'DESC'
$query = new WP_Query( $args );