I want to query all posts that contain an specific tag, so, lookin on the codex ref, it says something like this should work:
$args = array( 'tag' => 'my-tag' );
$wp_query->query($args);
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
endwhile;
But it always returns false...
I was reading is not possible to do that, and I have to use the has_tag
while i do a while over all the posts, is it true??
Any idea how to do this?
Thanks,
Very simple, just requires reading: http://codex.wordpress.org/Class_Reference/WP_Query
<?php $your_query = new WP_query(' tag_id=###' );
if ( $your_query->have_posts() ) : ?>
// This begins the loop to post the posts with your tag
<?php while ( $your_query->have_posts() ) : $your_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
// Closes loop
<?php wp_reset_postdata(); ?>
<?php else : ?>
// Loads error if no posts exists
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>