Created
September 4, 2020 06:13
-
-
Save maheshwaghmare/4fb9abef859297aa92a50b66b1ae8af1 to your computer and use it in GitHub Desktop.
WordPress: Add custom post types into the feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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