Looking at the orderby
parameter on WP_Query
, I don’t see any way to do this. You could (as Peter HvD suggests in his answer) convert your face cards to numbers; but if you want to keep the K|Q|J
values, I’d recommend using a usort()
callback:
// Assuming that $cartas->posts contains your posts
usort( $carta->posts, 'wpse313015_sort_cartas' );
// ...
function wpse313015_sort_cartas( $a, $b ) {
$single = true;
$a_dbt_carta = get_post_meta( $a->ID, 'dbt_carta', $single );
$b_dbt_carta = get_post_meta( $b->ID, 'dbt_carta', $single );
// If they're the same, don't worry about sorting.
if ( $a_dbt_carta == $b_dbt_carta ) {
return 0;
}
// Converts 'K', 'Q', and 'J' to numbers, for easier comparisons.
$face_card_numbers = array( 'K' => 13, 'Q' => 12, 'J' = 11 );
if ( in_array( $a_dbt_carta, array_keys( $face_card_numbers ) ) ) {
$a_dbt_carta = $face_card_numbers[ $a_dbt_carta ];
}
if ( in_array( $b_dbt_carta, array_keys( $face_card_numbers ) ) ) {
$b_dbt_carta = $face_card_numbers[ $b_dbt_carta ];
}
if ( $a_dbt_carta > $b_dbt_carta ) {
return -1;
}
return 1;
}
This code is untested. You’ll probably need to make changes to it to fit your particular needs.