Skip to content

Instantly share code, notes, and snippets.

@rahul3883
Created March 15, 2017 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul3883/2ce30b8a0723be226ce757eac0c1506f to your computer and use it in GitHub Desktop.
Save rahul3883/2ce30b8a0723be226ce757eac0c1506f to your computer and use it in GitHub Desktop.
Change order of media from descending to ascending
<?php
if ( ! function_exists( 'rtmedia_change_order_by_asc_callback' ) ) {
/**
* Change order of media from descending to ascending.
*
* This function changes the order by query string when
* media is uploaded from byssypress activity page or from uploader widget.
*
* @param string $qorderby order by query string
*
* @return string order by query string
*/
function rtmedia_change_order_by_asc_callback( $qorderby ) {
// get the post array.
$request = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
// check if $request is array and it is set.
if ( is_array( $request ) && isset( $request['action'] ) ) {
$action = $request['action'];
$attached_files = array();
// check if attached files is present or not.
if ( isset( $request['rtMedia_attached_files'] ) ) {
$attached_files = $request['rtMedia_attached_files'];
}
// check if media is uploaded from buddypress activity page or from uploader widget.
if ( 'wp_handle_upload' === $action || ( 'post_update' === $action && is_array( $attached_files ) && ! empty( $attached_files ) ) ) {
// replace 'desc' at the end of the string with 'asc'.
$qorderby = preg_replace( '/desc$/', 'asc', $qorderby );
return $qorderby;
}
}
return $qorderby;
}
}
add_filter( 'rtmedia-model-order-by-query', 'rtmedia_change_order_by_asc_callback' );
@rahul3883
Copy link
Author

rahul3883 commented Mar 15, 2017

Add this code in functions.php file of your theme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment