Query dei post per nome del termine della tassonomia
6 set 2012, 13:18:21
Visualizzazioni: 23.6K
Voti: 2
Vorrei ottenere la lista dei post filtrati per nome del loro termine di tassonomia personalizzata (=store).
Questo è quello che ho finora, ma non funziona.
Per favore aiutatemi con il codice.
$mystorename è una variabile che contiene il nome del negozio per cui voglio eseguire la query.
Ogni aiuto sarà apprezzato.
Grazie
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'store', // tassonomia 'negozio'
'field' => 'name', // filtra per nome
'terms' => $mystorename // nome del termine da cercare
)
)
);
$postslist = get_posts( $args );if(count($postslist) > 0){ ?>

Naijadeals
21
Tutte le risposte alla domanda
3
1
Non sono sicuro che la funzione get_posts supporti il tax_query. Potresti provare a creare un nuovo oggetto WP_Query invece.
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'store', // Tassonomia
'field' => 'name', // Campo
'terms' => $mystorename // Termini da cercare
)
)
);
$query = new WP_Query($args);
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
<!-- post -->
<?php endwhile; ?>
<!-- navigazione post -->
<?php else: ?>
<!-- nessun post trovato -->
<?php endif; ?>

Dave Hunt
1.1K
6 set 2012 18:16:16
0
<?php
$args=array(
'store' => $mystoreslug,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {?>
<div class="itembox">
<h1>Coupon del Negozio</h1>
<div class="itemboxinner">
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Link permanente a <?php the_title_attribute(); ?>"><h3><?php the_title(); ?></h3></a></p>
<?php
endwhile;
}
wp_reset_query();
?>

Naijadeals
21
8 set 2012 04:24:35
Domande correlate
3
risposte
2
risposte