Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author David Cavins

    (@dcavins)

    Hi Ulrich-

    I answered this question here: https://buddypress.org/support/topic/change-order-by-groups-documents/

    Best,

    -David

    Hi David,

    I think there is a problem with the plugin, whilst your suggestion should work it doesn’t. But also I noticed that just manually trying to change the sort order does not work. Something is forcing it for example to sort Descending and on the edited date anf no amount of clicking on the titles changes this.

    Plugin Author David Cavins

    (@dcavins)

    Huh. Well, the sample code I provided worked for me with a bare BP Docs setup. Could there be some JS that’s getting in the way, or some other plugin that is interacting with WP_Query args? ()

    That is odd, I’ve only got BP and Docs running, latest versions of all software. There code I’ve inserted into my functions.php is:

    add_filter( 'bp_after_bp_docs_has_docs_parse_args', function ( $args ) {
        $args['orderby'] = 'title';
        $args['order'] = 'ASC';
        return $args;
    } );

    With it loaded, clicking on Docs in a group comes up with the Last Edited heading highlighted with a down arrow. I can click on the Title heading and it gets highlighted but actually it still seems to be sorting by Last Edited date since neither up arrow or down arrow on Title will show my A’s at the top if they were edited last.

    Actually I’m completely wrong and it’s working now, I made a total novice mistake, got confused switching windows and have been copying the file to the wrong server all day and it’s been running with the same file for all my tests, my original file was sorting in DSC. Sorry about that.

    I think what helped with my confusion was that the Last Edited heading was coming up highlighted making me think that was the sort setting.

    Is there any way I could change the default setting rather than force this particular sort order on the site members? Ideally I’d set this as my default view but allow users to choose alternative sorts. This method forces this sort order for every view if I understand it correctly.

    Plugin Author David Cavins

    (@dcavins)

    Ha, I feel your pain about looking at the wrong test environment.

    That’s true about the column header sort order not being respected. When you click a column header to set a sort, the url is updated to something like this: http://bptest.local/docs?orderby=author

    So we can update the snippet to watch out for orderby as set by a $_GET param.

    
    add_filter( 'bp_after_bp_docs_has_docs_parse_args', function ( $args ) {
        if ( empty( $_GET['orderby'] ) ) {
            $args['orderby'] = 'title';
            $args['order'] = 'ASC';
        }
        return $args;
    } );
    

    I’m using empty() here because that parameter might not be set, so empty() will be true, or the url parameter could have a null value, like http://bptest.local/docs?orderby= so that would also be caught.

    • This reply was modified 8 years, 4 months ago by David Cavins.

    Yep that does the trick! Thanks for your help.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Change Order by (Groups –> Documents)’ is closed to new replies.