Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created January 5, 2019 13:12
Show Gist options
  • Save mgibbs189/8ac315debafabca6b4fd3d3bf27d717b to your computer and use it in GitHub Desktop.
Save mgibbs189/8ac315debafabca6b4fd3d3bf27d717b to your computer and use it in GitHub Desktop.
} else {
$orderby_array = array();
if ( is_array( $q['orderby'] ) ) {
foreach ( $q['orderby'] as $_orderby => $order ) {
$orderby = addslashes_gpc( urldecode( $_orderby ) );
$parsed = $this->parse_orderby( $orderby );
if ( ! $parsed ) {
continue;
}
$orderby_array[] = $parsed . ' ' . $this->parse_order( $order );
}
$orderby = implode( ', ', $orderby_array );
} else {
$q['orderby'] = urldecode( $q['orderby'] );
$q['orderby'] = addslashes_gpc( $q['orderby'] );
foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) {
$parsed = $this->parse_orderby( $orderby );
// Only allow certain values for safety.
if ( ! $parsed ) {
continue;
}
$orderby_array[] = $parsed;
}
$orderby = implode( ' ' . $q['order'] . ', ', $orderby_array );
if ( empty( $orderby ) ) {
$orderby = "{$wpdb->posts}.post_date " . $q['order'];
} elseif ( ! empty( $q['order'] ) ) {
$orderby .= " {$q['order']}";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment