WP_Query builder
Una query e il suo loop, costruiti dai campi.
Gratuito davvero. Nessuna registrazione, nessuna email, nessun limite, nessun cookie. Non salviamo l'URL che analizzi.
Codice
<?php
$q = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
) );
if ( $q->have_posts() ) :
while ( $q->have_posts() ) : $q->the_post(); ?>
<article <?php post_class(); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile;
wp_reset_postdata();
else :
echo '<p>No results.</p>';
endif;A cosa serve
WP_Query è il cuore delle query personalizzate in WordPress, ma i suoi argomenti sono tanti e facili da dimenticare. Qui imposti i parametri principali e ottieni la query più il loop pronto, con il wp_reset_postdata() finale che tutti dimenticano.
Domande frequenti
›A cosa serve wp_reset_postdata()?
Ripristina il post globale dopo un loop personalizzato. Se lo dimentichi, il resto della pagina può mostrare i dati sbagliati. Questo builder lo include sempre.