Consultar posts por nombre de término de taxonomía
6 sept 2012, 13:18:21
Vistas: 23.6K
Votos: 2
Me gustaría obtener la lista de posts por el nombre de su taxonomía personalizada (=store).
Esto es lo que tengo hasta ahora, pero no está funcionando.
Por favor, ayuda con el código.
$mystorename es una variable que contiene el nombre de la tienda por la cual quiero hacer la consulta.
Cualquier ayuda será apreciada.
Gracias
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'store', // taxonomía 'store'
'field' => 'name', // buscar por nombre
'terms' => $mystorename // nombre de la tienda
)
)
);
$postslist = get_posts( $args );if(count($postslist) > 0){ ?>

Naijadeals
21
Todas las respuestas a la pregunta
3
1
No estoy seguro si la función get_posts soporta tax_query. Quizás quieras intentar crear un nuevo objeto WP_Query en su lugar.
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'store',
'field' => 'name',
'terms' => $mystorename
)
)
);
$query = new WP_Query($args);
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
<!-- post -->
<?php endwhile; ?>
<!-- post navigation -->
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>

Dave Hunt
1.1K
6 sept 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>Cupones de la tienda</h1>
<div class="itemboxinner">
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Enlace permanente a <?php the_title_attribute(); ?>"><h3><?php the_title(); ?></h3></a></p>
<?php
endwhile;
}
wp_reset_query();
?>'

Naijadeals
21
8 sept 2012 04:24:35
Preguntas relacionadas
3
respuestas
2
respuestas
2
respuestas