Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active November 22, 2022 08:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/e6a90f2b3623d212cb81 to your computer and use it in GitHub Desktop.
Save braddalton/e6a90f2b3623d212cb81 to your computer and use it in GitHub Desktop.
add_filter( 'pre_get_posts', 'add_cpt_to_loop_and_feed' );
/**
* @author Brad Dalton
* @example http://wpsites.net/wordpress-tips/add-custom-post-type-to-rss-feed/
* @copyright 2014 WP Sites
*/
function add_cpt_to_loop_and_feed( $query ) {
if ( is_home() && $query->is_main_query() || is_feed() )
$query->set( 'post_type', array( 'post', 'your-cpt' ) );
return $query;
}
@sanderlt
Copy link

thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment