I am using a small shortcode to output a list of movie titles arranged by decades. decades
is my custom taxonomy with terms like 1930s
1940s
etc.
Here is my shortcode:
[fashionfilms type=fashionfilms tax=decades]
and here is how that shortcode is parsed:
add_shortcode('fashionfilms', 'cw_output_fashion_films');
function cw_output_fashion_films($atts){
$post_type = $atts['type'];
$tax = $atts['tax'];
$tax_terms = get_terms($tax);
if ($tax_terms) {
echo "<ul>";
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo "<li class='letter'>" . $tax_term->name . "</li>";
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
}
wp_reset_query();
} //end foreach loop
echo "</ul>";
}
}
The problem is I am getting a doubled output for my entries.
To see the doubled outout, please check my live link here.
Here is my page template code too:
<div class="span9">
<?php while ( have_posts() ) : the_post(); ?>
<div <?php post_class(); ?>>
<h1><?php the_title();?></h1>
<div class="content">
<?php the_content() ?>
</div>
</div><!-- /.post_class -->
<?php endwhile; ?>
<?php bootstrapwp_content_nav('nav-below');?>
</div><!-- /.span9 -->
What am I doing wrong? How can I fix this?
wp_reset_postdata()
instead ofwp_reset_query()
? It was the only real difference I could find (and which also happens to be relevant to your issue since the loop seems to run twice(?)) between your topic and this one.wp_reset_postdata()
solved the issue. What do you think is really causing the issue @Stephen?return
ing instead ofecho
ing the output?