Skip to content

Instantly share code, notes, and snippets.

@alwerner
Last active December 14, 2015 05:59
Show Gist options
  • Save alwerner/5039218 to your computer and use it in GitHub Desktop.
Save alwerner/5039218 to your computer and use it in GitHub Desktop.
Using Wordpress Tags with Custom Post Types, goes in functions.php
// Using Tags with Custom Post Types, goes in functions.php
function add_custom_types( $query ) {
if( is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// this gets all post types:
// $post_types = get_post_types();
// alternately, you can add just specific post types using this line instead of the above:
$post_types = array( 'post', 'news' );
$query->set( 'post_type', $post_types );
return $query;
}
}
add_filter( 'pre_get_posts', 'add_custom_types' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment