Site icon Hip-Hop Website Design and Development

Custom meta_query order for Elementor based on post meta key

I’m failing at writing an Elementor $meta_query function so posts will be ordered by meta_value_num of a given key.

Each post has a numeric value for the key google_unique_page_views

My example is below:

// Custom query to order 'recommended reading' posts by populatrity
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    $meta_query = $query->get( 'meta_query' );
    if ( ! $meta_query ) {
        $meta_query = [];
    }
    $meta_query[] = [
        'order'=> 'DESC',
        'key' => 'google_unique_page_views',
        'orderby' => 'meta_value_num',
    ];
    $query->set( 'meta_query', $meta_query );   
});

Do I need to include the value query?