Modifying the queries for private content listing

When you are displaying a page where private content is listed (e.g. Dashboard, My files, My pages, My conversations), Customer Area performs a database query to fetch all the private content assigned to the current user.

In some cases, you may want to change that query, for example to change the sorting order. Just include this snippet of code in functions.php or cuar-functions.php.

Let’s say that you want your files to be organized into categories but that you want to show the last modified one on top.

function cuar_custom_sorting_order( $args ) {
    $new_args = $args;

    // The next line says that the sort order will be by the date of the last modification
    // You could also sort by any field of the WordPress post table, like 'title'
    $new_args['orderby'] = 'modified';

    // This line says that we want to sort by descending order (opposite of 'ASC')
    $new_args['order'] = 'DESC';
    return $new_args;

// You can change the page slug to another one, for instance 'customer-private-pages' or 'customer-conversations'
$page_slug = 'customer-private-files';

// Uncomment the add_filter line you need, depending on where you want to change the sorting order

// 1. Change the order on the "My files" page (for any display mode)
// add_filter( 'cuar/core/page/query-args?slug=' . $page_slug, 'cuar_custom_sorting_order' );

// 2. Change the order on the "My files" page (not when we are showing date archives or category archives)
// add_filter( 'cuar/core/page/query-args?slug=' . $page_slug . '&display-mode=default', 'cuar_custom_sorting_order' );

// 3. Change the order on the "My files" page (when showing date archives)
// add_filter( 'cuar/core/page/query-args?slug=' . $page_slug . '&display-mode=date_archive', 'cuar_custom_sorting_order' );

// 4. Change the order on the "My files" page (when showing category archives)
// add_filter( 'cuar/core/page/query-args?slug=' . $page_slug . '&display-mode=category_archive', 'cuar_custom_sorting_order' );

// 5. Change the order on the "Dashboard" page
// add_filter( 'cuar/core/dashboard/block-query-args?slug=' . $page_slug, 'cuar_custom_sorting_order' );