2

Ich habe eine benutzerdefinierte Beitragstyp cota wo alle Daten in einem <table> in meiner Website angezeigt werden. Ich muss diese Tabelle bestellen:WP_Query nicht richtig bestellt

  • administradora - eine Art von "Kategorie", die der Benutzer angibt. Bestellte ASC (a-z);
  • valor - Der Preis der cota. Jeder cota hat einen Preis. Bestellter DESC (9 - 0);

Das Problem: Es ist bereits von administradora bestellt, aber nicht korrekt von valor bestellt.

Beispiel: Die Bestellung von valor zeigt zuerst eine cota mit US $ 9.000,00 und dann eine weitere cota mit US $ 1.000.000,00. Es ist falsch. Die eine Million Dollar cota sollte zuerst kommen, und dann die neuntausend Dollar cota.

Here's an image that shows better the situation

-Code für die Bestellung des cota:

 $query = new WP_Query(array(
     'post_type' => 'cota', 
     'posts_per_page' => -1, 
     'tax_query' => array(
      array(
       'taxonomy' => 'tipo', 
       'field' => 'slug', 
       'terms' => $atts['tipo'], 
     ), 
    ), 
     'orderby' => 'meta_value_num', 
     'meta_query' => array(
     'relation' => 'AND', 
     'valor_clause' => array(
      'key' => 'valor', 
      'compare' => 'EXISTS' 
     ), 
     'adm_clause' => array(
      'key' => 'administradora', 
      'compare' => 'EXISTS' 
     ) 
    ), 
     'orderby' => array(
     'adm_clause' => 'ASC', 
     'valor_clause' => 'DESC' 
    ) 
    ) 
); 

EDIT 1: Nach einigen Recherchen fand ich heraus, dass Wordpress seine Daten alle als longtext speichert in der Datenbank. Aber immer noch kann das Problem nicht gelöst werden.

Ich kann bei Bedarf weitere Informationen zur Verfügung stellen.

Antwort

0

Try Below-Code:

$query = new WP_Query(array(
    'post_type' => 'cota', 
    'posts_per_page' => -1, 
    'tax_query' => array(
     array(
      'taxonomy' => 'tipo', 
      'field' => 'id', 
      'terms' => $atts['tipo'], 
    ), 
), 
    'orderby' => 'meta_value_num', 
    'meta_query' => array(
    'relation' => 'AND', 
    'valor_clause' => array(
     'key' => 'valor', 
     'compare' => 'EXISTS' 
    ), 
    'adm_clause' => array(
     'key' => 'administradora', 
     'compare' => 'EXISTS' 
    ) 
), 
    'orderby' => array(
    'adm_clause' => 'ASC', 
    'valor_clause' => 'DESC' 
) 
) 
); 
+0

Hat nicht funktioniert. Wenn ich das "Feld" von "Slug" zu "ID" ändere, werden die Daten nicht angezeigt. –

0

GELÖST

Der folgende Code sollte funktionieren:

 $query = new WP_Query(array(
     'post_type' => 'cota', 
     'posts_per_page' => -1, 
     'tax_query' => array(
      array(
       'taxonomy' => 'tipo', 
       'field' => 'slug', 
       'terms' => $atts['tipo'], 
     ), 
    ), 
     'meta_query' => array(
     'relation' => 'AND', 
     'credito_clause' => array(
      'key' => "valor", 
      'orderby' => 'meta_value_num', 
      'type' => 'DECIMAL', 
      'compare' => 'EXISTS' 
     ), 
     'adm_clause' => array(
      'key' => 'administradora', 
      'compare' => 'EXISTS' 
     ) 
    ), 
     'orderby' => array(
     'adm_clause' => 'ASC', 
     'credito_clause' => 'DESC' 
    ) 
    ) 
);