• Add-ons
  • Blog
  • Resources
    • Documentation
    • FAQs
    • Code snippets
    • Use cases
    • Support
  • Account
    • My account
    • Checkout
    • Cart
  • English
  • French
  • Add-ons
  • Blog
  • Resources
    • Documentation
    • FAQs
    • Code snippets
    • Use cases
    • Support
  • Account
    • My account
    • Checkout
    • Cart
  • English
  • French
home/Knowledge Base/Code snippets/Modifying the queries for private content listing

Modifying the queries for private content listing

593 views 0 April 13, 2021

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 "My files" page (when showing author archives)
// add_filter( 'cuar/core/page/query-args?slug=' . $page_slug . '&display-mode=author_archive', 'cuar_custom_sorting_order' );

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

Was this helpful?

Yes  No
Related Articles
  • Custom admin notification’s recipients
  • Disable CSS resets and allow integration of third party plugins
  • Automatically add a user to a group
  • Changing the default page shown by the Customer Area
  • Changing the page shown after logout
  • Sidebars: how to disable them

Didn't find your answer? Contact Us

Knowledge base
  • Code snippets 25
  • Use cases 2
  • Community links 5
FAQ
  • About licences 7
  • Pre-sales questions 3
  • After-sales questions 1
  • Plugin usage 8
  • Technical questions 10
  • Payments 4
Documentations
  • Getting started
  • Using code snippets
  • The template system
  • Full documentation
Support
  • Pre-sales Enquiries
  • Main plugin support
  • Premium add-ons support
  • Feature Requests

  Remove the WP Customer Area menu from the WordPress admin bar

Insert the navigation menu in your WP Customer Area theme  

  • Terms and conditions for sales
  • Refund policy
  • Privacy Policy
  • Legal notices
  • Copyright 2021 wp-customerarea.com. All Rights Reserved.