Con l'aggiunta dei campi personalizzati (custom) รจ possibile aggiungere informazioni extra ai nostri post, informazioni che possono risultare utili per creare dei sottoinsiemi di post. Ma come fare a reperire tale tipo di post?
Sia che utilizziamo query_posts()
o la classe WP_Query
, possiamo usare i parametri meta_key
e meta_value
. Il primo rappresenta il nome del campo custom, il secondo il suo valore.
Usare query_posts()
query_posts('meta_key=review_type&meta_value=movie');
if (have_posts()) :
while (have_posts()) : the_post();
//...
endwhile;
endif;
Usare WP_Query
$args = array('meta_key' => 'review_type', 'meta_value' => 'movie');
$loop = new WP_Query($args);
if($loop->have_posts()) {
while($loop->have_posts()) {
$loop->the_post();
// ...
}
}