Custom Fields
Re-Envisioned
Support MB Relationships Filter the orderby of entries retrieved from database Reply To: Filter the orderby of entries retrieved from database

#11218

Anh Tran
Keymaster

Hi Juanita,

You can overwrite the orderby parameter with this code:

add_filter( 'posts_clauses', function( $clauses, $query ) {
    $relationship = $query->get( 'relationship' );
    if ( ! $relationship || 'REL_ID' != $relationship['id'] ) ) {
        return $clauses;
    }
    $clauses['orderby'] = 'ORDER BY post_date DESC';
    return $clauses;
}, 99, 2 );

It overwrites the orderby in the query. You might change it to fit your needs.