Come faccio a cambiare l'ordine (ASC e DESC) nel seguente metodo di recupero utilizzando WP_Query?

wordpress.stackexchange https://wordpress.stackexchange.com/questions/7599

  •  16-10-2019
  •  | 
  •  

Domanda

Il codice seguente recupera solo i tipi di messaggi personalizzati con la tassonomia personalizzato "Slider".

Vorrei cambiare il loro ordine di ASC.

Il codice:

<?php // Retrive custom post type with a custom taxonomy assigned to it
 $posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)') ?>
 <?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
 <?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

Non so se devo usare un array (non so come comunque).

Qualche suggerimento?

È stato utile?

Soluzione

basta cambiare questa riga nel codice:

 $posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)') ?>

a questo:

 $posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)&order=ASC') ?>

Fondamentalmente si aggiunge il parametro ordine strega può assumere due valori (ASC, DESC).

Spero che questo aiuti.

Altri suggerimenti

Che fine che si vuole raggiungere? Cronologico? Alfabetico?

In ogni caso vedere Order & OrderBy parametri nel Codex per gli argomenti disponibili.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top