Filtering a loop by a custom taxonomy term assignment
-
I have a custom taxonomy called ‘test’, and I want to filter the main loop to show only posts that are tagged with the term ‘test_term’.
I tried using the ‘pre_get_posts’ and the ‘request’ filters, and it doesn’t seem to be working:
//in functions.php add_action( 'pre_get_posts', 'test_pre_get_posts' ); function test_pre_get_posts( $query ) { $query->set('taxonomy','test'); $query->set('term','test_term'); return $query; } // and for the loop-index.php file in the theme: <?php while ( have_posts() ) : the_post(); ?> ... <?php endwhile; ?>
In query.php:1432 I printed out the value of $qv, and it does not seem to contain the changes I made in the pre_get_posts hook. The second conditional on line 1436 returns false as a result:
isset($qv[$t->query_var])
Thanks for the help,
Dave Morris
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Filtering a loop by a custom taxonomy term assignment’ is closed to new replies.