I have a taxonomy.php file to display taxonomy terms. I added a filter in functions.php to include post types for the taxonomy page query. This filter:
add_filter( 'pre_get_posts' , 'ucc_include_custom_post_types' );
function ucc_include_custom_post_types( $query ) {
global $wp_query;
/* Don't break admin or preview pages. */
if ( !is_preview() && !is_admin() && !is_page() && !is_single() ) {
$args = array(
'public' => true ,
'_builtin' => false
);
$output = 'names';
$operator = 'and';
$post_types = get_post_types( $args , $output , $operator );
$post_types = array_merge( $post_types , array( 'post' ) );
if ($query->is_feed) {
// Do feed processing here.
} else {
$my_post_type = get_query_var( 'post_type' );
if ( empty( $my_post_type ) )
$query->set( 'post_type' , $post_types );
}
}
return $query;
}
Returns any and all post types you want. But I am trying to find a way to separate them. I tried to use a normal loop but I don't know how to fetch the current taxonomy tag from the page.
I have 2 questions which are all related but seeing what is the best way to go about this. Pretend I have 3 posts types ('post' 'post2' 'post3')
- Is there a loop that can be used in taxonomy.php that will display a particular post type? So it can be possible to have one loop for each post type? So when I click on a taxonomy term, the taxonomy.php will return:
--Taxonomy Page --
Loop for custom type post 1 (show post with current taxonomy tag in this specific post type)
Loop for custom type post 2
Loop for custom type post 3
- If there are multiple loops, will this affect the pagination? Or will pagination only work for posts?
I have used many single loops in the taxonomy.php page to no avail. I feel I have to echo the current taxonomy term variable to a new variable:
$term = $wp_taxonomies??
Any way for multiple loops in the taxonomy.php pages?