Adding CPT to post widget blocks
-
First off thanks for the plugin.
I was going to ask how to get custom post to show up in the
• Gutenberg Blocks Widgets: Latest Posts and Blog Posts
• GoDaddy Gutenberg Blocks CoBlocks: Post Carousel Block and Posts Block
• Jetpack: Related Posts Blockwithout using/ installing a third-party plugin but I figured it out. For those that are looking to do the same I thought I’d share it here since it’s not a feature of this plugin. I added it to my theme function as I built a custom theme, but it can be added to a plugin for those that want to switch themes later.
/**
* To add custom post types from CPTUI to post widget blocks such as Latest Posts, Blog Posts, Post Carousel Block, Posts Block and Related Posts Block
*/function thbc_add_my_custom_post_type ($query) {
if(
empty($query->query[‘post_type’])
or $query->query[‘post_type’] === ‘post’
){
$query->set(‘post_type’, array(‘post’, ‘page’, ‘ADD CUSTOM POST TYPE HERE’));
}
}
add_action(‘pre_get_posts’, ‘thbc_add_my_custom_post_type’);The page I need help with: [log in to see the link]
The topic ‘Adding CPT to post widget blocks’ is closed to new replies.