Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Created September 4, 2020 06:13
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 maheshwaghmare/4fb9abef859297aa92a50b66b1ae8af1 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/4fb9abef859297aa92a50b66b1ae8af1 to your computer and use it in GitHub Desktop.
WordPress: Add custom post types into the feed.
<?php
/**
* Add Custom Post Types (CPT) to feeds
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*
* @return object
*/
if( ! function_exists( 'prefix_add_custom_post_types_to_feed' ) ) :
function prefix_add_custom_post_types_to_feed( $query ) {
// Is feed then add custom post types.
if ( is_feed() ) {
$query->set( 'post_type', array( 'post', 'astra-portfolio', 'deal' ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'prefix_add_custom_post_types_to_feed' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment