Support » Plugins » Hacks » Taxonomy in loop

  • Hi,
    Can anyone please tell me if you have an idea why doesn’t this work :

    $args = array(
    	'tax_query' => array(
    			'taxonomy' => 'locations',
    $query = new WP_Query( $args );	?>
    <?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    		<a href = "<?php the_permalink(); ?>"
    		rel = "bookmark" title = "
    		<?php the_title_attribute(); ?>"
    		alt = "
    		<?php the_title_attribute(); ?>"
    		<?php the_title(); ?>
    	<?php endwhile; ?>
    	<?php else : ?>
    	<h2>Sorry nothing Found</h2>
    	<?php endif; ?>

    I obviously have created to taxonomy in my functions.php, one of them is called ‘locations’ and I have a few posts connected to it, problem is the loop ignores my new WP_query and shows all of them, if I specify only one term (‘locations’ => ‘vejer’) it does work but I can’t seem to be able to tell the loop to show all posts under ‘location’ when trying to do that I get all posts.


Viewing 3 replies - 1 through 3 (of 3 total)
  • Applying a taxonomy to a post type means that all of those posts qualify as being part of that taxonomy. As someone said here, that’s like looking for all posts under “Categories” or “Post tags”.

    So if you’ve applied the Locations taxonomy to your posts, then every post technically could be considered to be part of that. I am guessing you’re hoping to only select posts with active Location taxonomies applied?

    There’s a solution in the link I shared above, and here’s another example of how you might iterate through your custom taxonomy.

    Hopefully this helps. Let me know if you’re still a little lost or whether this isn’t what you were looking for!

    Hey there pirate ninja,

    It’s exactly(!) what I was looking for, found another (not so aesthetic approach) but I’ll take a look into the example you have attached and let you know,



    Sure thing! 🙂 Good luck, and don’t forget to mark this thread as resolved if you figure something out that works.

    If you’re still running into issues just post back with specifics!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Taxonomy in loop’ is closed to new replies.