Using Orderby and meta_value to order natural/alphanumerical

enter image description here

I added a custom column for a custom post type. Then I put it to be the 3th column, and now I want to sort it alphanumerical.
I use this action : add_action( 'pre_get_posts', 'manage_wp_posts_be_qe_pre_get_posts', 1 );
I write this fuction:

   function manage_wp_posts_be_qe_pre_get_posts( $query ) {
   if ( $query->is_main_query() && ( $orderby = $query->get( 'orderby' ) ) ) { 
      switch( $orderby ) {
         case 'Rif':
            $query->set( 'meta_key', 'riferimento' );
            $query->set( 'orderby', 'meta_value meta_value_num');
            break;
      }

   }
}

but it doesn’t works.
It returns me always :

But I want first CA3 CA5 and then CA10 ….
I tried also to cast with LENGTH() or similr things, but nothing to do..

Read more here:: Using Orderby and meta_value to order natural/alphanumerical

Leave a Reply

Your email address will not be published. Required fields are marked *