WP Query con tassonomia personalizzata
11 gen 2013, 14:18:57
Visualizzazioni: 29.1K
Voti: 2
Sto iniziando a familiarizzare con WP Query e speravo di poter ricevere un po' di assistenza su questo.
Ho creato una tassonomia personalizzata (theme) e ora voglio visualizzare l'ultimo post con una di queste tassonomie nella mia pagina iniziale come post in evidenza.
Non riesco a capire come filtrare correttamente la query, forse qualcuno può correggermi:
<?php
$args = array(
'tax_query' => array(
array(
'posts_per_page' => 1,
'taxonomy' => 'theme',
'field' => 'slug',
'terms' => array ('text-image', 'just-text', 'just-image')
)
)
);
$query = new WP_Query( $args );
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Qualsiasi aiuto sarebbe molto apprezzato, grazie!
MODIFICA: Ecco il codice completo nel caso qualcun altro ne abbia bisogno;
<?php
$args = array(
'post_type' => 'post', // è predefinito, puoi saltarlo
'posts_per_page' => '1',
'order_by' => 'date', // anche questo è predefinito
'order' => 'DESC', // anche questo è predefinito
'tax_query' => array(
array(
'taxonomy' => 'nameoftaxonomy',
'field' => 'slug',
'terms' => array ('whatever1', 'whatever2', 'whatever3')
)
)
);
$query = new WP_Query( $args );
?>
<?php if (have_posts()) : while( $query->have_posts() ) : $query->the_post(); ?>
Grazie per l'aiuto!

kallekillen
158
Commenti
Tutte le risposte alla domanda
2
0
I tuoi argomenti di WP_Query
sono sbagliati. posts_per_page
non fa parte di tax_query
. Il seguente codice dovrebbe funzionare:
$args = array(
'post_type' => 'post', // è il valore di default, puoi ometterlo
'posts_per_page' => '1',
'order_by' => 'date', // anche questo è di default
'order' => 'DESC', // anche questo è di default
'tax_query' => array(
array(
'taxonomy' => 'theme',
'field' => 'slug',
'terms' => array ('text-image', 'just-text', 'just-image')
)
)
);

Max Yudin
6.38K
11 gen 2013 15:47:52
Domande correlate
1
risposte
1
risposte