WP_Query orderby data non funzionante

10 nov 2016, 12:25:10
Visualizzazioni: 90.2K
Voti: 10

Ho una semplice WP_Query per ottenere una lista di articoli di un co-autore (tassonomia author) ordinati per data, questa è la query:

// Ottiene il nome utente dell'autore
$username = get_the_author_meta( 'login', $author_id );
$args = array(
  'post_type' => 'any',
  'orderby' => 'date',
  //'orderby' => 'post_date',
  'order'   => 'DESC',
  'tax_query' => array(
    array(
      'taxonomy' => 'author',
      'field' => 'name',
      'terms' => $username
      )
  )
);
$query = new WP_Query( $args );

Il risultato è sempre una lista di articoli ordinati per data in ordine ASC... Ho già cercato soluzioni su internet senza successo... Qualche idea?

Grazie mille

1
Commenti

Vuoi ordinare per data in ordine DESC? Forse hai un plugin o il tema che interferisce con la query? Cosa succede se usi 'suppress_filters' => true?

birgire birgire
10 nov 2016 12:31:41
Tutte le risposte alla domanda 3
2
16

Funzionerà sicuramente... Ha funzionato per me...

$username = get_the_author_meta( 'login', $author_id );
$args = array(
    'post_type' => 'any',
    'orderby' => 'date',
    'order'   => 'DESC',
    'suppress_filters' => true,
    'tax_query' => array(
     array(
           'taxonomy' => 'author',
           'field' => 'name',
           'terms' => $username
          )
     )
);
                
$query = new WP_Query( $args );
19 lug 2017 09:12:55
Commenti

Non funziona per me..

Radmation Radmation
20 nov 2017 21:08:34

aggiungi questo negli argomenti 'suppress_filters' => true,

Pravin Work Pravin Work
27 feb 2020 07:23:08
2

Aggiungendo

'suppress_filters' => true

nell'array $args è stato possibile ottenere l'ordinamento desiderato.

15 feb 2018 23:14:00
Commenti

Questo indica che un hook di un plugin o di un tema sta modificando la query.

Howdy_McGee Howdy_McGee
16 feb 2018 00:02:31

Controlla se hai installato il plugin Post Types Order o qualsiasi altro plugin, disabilitalo. La query dovrebbe funzionare correttamente.

Muddasir Abbas Muddasir Abbas
17 ago 2020 20:37:19
0

Se stai utilizzando il plugin Post Types Order, potrebbe essere necessario aggiungere il seguente argomento alla tua query:

'ignore_custom_sort' => true,
21 mar 2021 00:49:15