Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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' );
Owner

rahul3883 commented Mar 15, 2017 edited

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