wordpress - Order by post meta not working -


i trying use custom sortable column 'book' post type.

my pre_get_posts function isn't sorting. each post has existing meta value 'downloads_orders', numbers. have verified code being run (by dumping out query)

add_action( 'pre_get_posts', 'my_book_orderby' ); function my_book_orderby( $query ) {     if( ! is_admin() )         return;      $orderby = $query->get( 'orderby');      if( 'downloads_orders' == $orderby ) {         $query->set('meta_key', 'downloads_orders');         $query->set('orderby', 'meta_value_num');     } } 

any ideas why isn't sorting?

edit: realized none of sorting working. not default title column. edit: 'post types order' plugin conflicting, causing no sorting work. deactivated , above code working

try this:

add_action( 'pre_get_posts', 'my_book_orderby' ); function my_book_orderby( $query ) {     if( ! is_admin() )         return;      $orderby = $query->get( 'orderby');      if( 'downloads_orders' == $orderby ) {         $query->set('meta_key', 'downloads_orders');         $query->set('orderby', 'meta_value');     } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -