La classe WP_Query è definita all’interno di wp-includes/query.php.
Racchiude diverse informazioni come categoria archivio, data archivio, feed, ricerca e fetches post. Insomma può essere utilizzata per diversi scopi.
Anche se principalmente viene usata nel Tag Template Loop per essere “fetchata” . Una sua possibile implementazione potrebbe essere.
<?php // The Query $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; /* Restore original Post Data */ wp_reset_postdata(); } else { // no posts found }
Ossia affinchè ci sono articoli fetcha.
Altre possibili implementazioni sono
$query = new WP_Query( array( 'author_name' => 'rami' ) );
Questa volta vengono caricate unicamente gli autori che si chiamano rami o meglio poi la variabile $query viene fectchata con have_post .
Oppure se conosciamo l’id specifico di determinati autori
$query = new WP_Query( array( 'author' => '2,6,17,38' ) );