Last active
October 17, 2016 14:50
-
-
Save stephanieleary/6b393626053e9a5986a663159855dbb7 to your computer and use it in GitHub Desktop.
add post_type arg to term links (narrow down the query)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'term_link', 'taxonomy_link_for_post_type', 10, 3 ); | |
function taxonomy_link_for_post_type( $termlink, $term, $taxonomy ) { | |
$tax_obj = get_taxonomy( $taxonomy ); | |
// if this is not a shared taxonomy, bail | |
if ( count( $tax_obj->object_type ) == 1 ) | |
return $termlink; | |
// cf. https://gist.github.com/sillybean/c725ea4620e9d434e71927ab41879f38 | |
$post_type = scl_find_post_type(); | |
if ( !isset( $post_type ) || 'any' == $post_type ) | |
return $termlink; | |
$termlink = add_query_arg( 'post_type', $post_type, $termlink ); | |
return $termlink; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment