Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created April 24, 2019 17:36
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 billerickson/6463e9660211e056ad3e657c2082f94c to your computer and use it in GitHub Desktop.
Save billerickson/6463e9660211e056ad3e657c2082f94c to your computer and use it in GitHub Desktop.
<?php
/**
* Sort Column Query.
*
* @since 1.1.0
*
* @param object $query WP_Query object.
*/
public function sort_column_query( $query ) {
if ( is_admin() && 'shared_counts' === $query->get( 'orderby' ) ) {
$meta_query = array(
'relation' => 'OR',
array(
'key' => 'shared_counts_total',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
array(
'key' => 'shared_counts_total',
'type' => 'NUMERIC',
'compare' => 'NOT EXISTS',
)
);
$query->set( 'orderby', 'meta_value_num date' );
$query->set( 'meta_query', $meta_query );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment