WP_Query + casuale

21 set 2013, 23:53:47
Visualizzazioni: 56.6K
Voti: 26

C'è un modo per ottenere questo

<?php 
$pc = new WP_Query ('category_name=cat1&posts_per_page=5'); 
?> 

ma mostrare ogni volta un gruppo CASUALE diverso di 5 post?

1
Commenti

nota che l'ordinamento rand è molto costoso per il database

Tom J Nowell Tom J Nowell
27 apr 2021 20:41:29
Tutte le risposte alla domanda 1
0
41

Prova questo:

$args = array(
    'category_name'  => 'cat1',
    'posts_per_page' => 5,
    'orderby'        => 'rand',
);

$pc = new WP_Query( $args ); 

dove 'rand' dovrebbe restituirti un ordine casuale dei tuoi articoli.

Per maggiori informazioni consulta il Codex sui parametri WP_Query per l'ordinamento qui.

22 set 2013 00:44:32