Skip to content

Instantly share code, notes, and snippets.

@dancameron
Forked from sproutventure/gist:1126637
Created March 21, 2012 15:36
Show Gist options
  • Save dancameron/2148597 to your computer and use it in GitHub Desktop.
Save dancameron/2148597 to your computer and use it in GitHub Desktop.
<?php
function filter_term_archive( $query ) {
if( is_tax( some_custom_post_type_tax_slug() ) ) {
$query->set( 'tax_query', array(
'relation' => 'AND', // Change to OR if we only want to filter one type.
array(
'taxonomy' => some_custom_tax_slug(),
'field' => 'slug',
'terms' => $array_of_terms
),
array(
'taxonomy' => some_custom_post_type_tax_slug(),
'field' => 'slug',
'terms' => $current_archive_term
)
));
}
return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );
// Or this
function filter_term_archive( $query ) {
if( is_tax( some_custom_post_type_tax_slug() ) ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => some_custom_tax_slug(),
'field' => 'slug',
'terms' => $array_of_terms
)
));
}
return $query;
}
add_filter( 'pre_get_posts', 'filter_term_archive' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment