Skip to content

Instantly share code, notes, and snippets.

@AMNDesign
Last active December 21, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AMNDesign/6366335 to your computer and use it in GitHub Desktop.
Save AMNDesign/6366335 to your computer and use it in GitHub Desktop.
Include custom post types in tag archive and category archive search results in WordPress.
<?php
//* Include custom post types in tag archive and category archive search results
add_filter( 'pre_get_posts', 'amn_get_posts' );
function amn_get_posts( $query ) {
if ( ( is_tag() || is_category() ) && false == $query->query_vars['suppress_filters'] )
$query->set( 'post_type', array( 'post', 'page', 'attachment', 'my_custom_post_type' ) );
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment