Skip to content

Instantly share code, notes, and snippets.

@sillybean sillybean/functions.php
Last active Oct 17, 2016

Embed
What would you like to do?
add post_type arg to term links (narrow down the query)
<?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
You can’t perform that action at this time.