• Resolved IAmAdamTaylor

    (@ad_taylor)


    Hi,

    Would you be able to expand the support for the ‘Use query ASC / DESC parameter’ checkbox so that it affects the admin interface as well?

    On a particular custom post type, I have chosen to expose the menu_order as a sortable column, so that users can see where each post is sitting in the order. When I try to sort that column into DESC order the table stays in ASC order.

    These are the query params being generated in the URL:
    ?post_type=client&orderby=menu_order&order=desc

    Digging into the plugin code a bit, it seems this can be achieved by changing the code in include/class-cpto.php on line 173:

    From:

    
    $orderBy = "{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC";
    

    To:

    
    $order  =   'ASC'; // Set default order
    if ($options['use_query_ASC_DESC'] == "1")
        $order  =   isset($_GET['order'])  ?   " " . $_GET['order'] : ' ASC';
    
    $orderBy = "{$wpdb->posts}.menu_order". $order .", {$wpdb->posts}.post_date DESC";
    

    Please consider adding this to the plugin.

    Thanks,
    Adam Taylor

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Maya

    (@tdgu)

    Hi
    Thanks for your feedback, however this might not work with others. Almost all queries on admin include a descending order, meaning all lists will appear reversed.

    I think i better approach will be to use a filter, which we included, available for the next release, see the ‘pto/posts_order’ filter. This part of the code become as follow:

    if (is_admin())
        {
            
            if ( $options['adminsort'] == "1" || (defined('DOING_AJAX') && isset($_REQUEST['action']) && $_REQUEST['action'] == 'query-attachments') )
                {
                    
                    global $post;
                    
                    $order  =   apply_filters('pto/posts_order', '', $query);
                    
                    //temporary ignore ACF group and admin ajax calls, should be fixed within ACF plugin sometime later
                    if (is_object($post) && $post->post_type    ==  "acf-field-group"
                            ||  (defined('DOING_AJAX') && isset($_REQUEST['action']) && strpos($_REQUEST['action'], 'acf/') === 0))
                        return $orderBy;
                        
                    if(isset($_POST['query'])   &&  isset($_POST['query']['post__in'])  &&  is_array($_POST['query']['post__in'])   &&  count($_POST['query']['post__in'])  >   0)
                        return $orderBy;   
                    
                    $orderBy = "{$wpdb->posts}.menu_order {$order}, {$wpdb->posts}.post_date DESC";
                }
        }
    else
        {   
            $order  =   '';
            if ($options['use_query_ASC_DESC'] == "1")
                $order  =   isset($query->query_vars['order'])  ?   " " . $query->query_vars['order'] : '';
            
            $order  =   apply_filters('pto/posts_order', $order, $query);
            
            if ($options['autosort'] == "1")
                {
                    if(trim($orderBy) == '')
                        $orderBy = "{$wpdb->posts}.menu_order " . $order;
                    else
                        $orderBy = "{$wpdb->posts}.menu_order". $order .", " . $orderBy;
                }
        }

    You can update on your side until we release this tag.

    • This reply was modified 6 years, 8 months ago by Maya.
    Thread Starter IAmAdamTaylor

    (@ad_taylor)

    That sounds great – thank you again for your continued work on this plugin.

    I look forward to the next release.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add ASC/DESC support to admin interface’ is closed to new replies.