• Resolved thehorsebc

    (@thehorsebc)


    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 Block

    without 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]

Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Definitely not going to refute this working, but it is good to know that this is adding your post type for consideration to pretty much every query being made for post content.

    It may not have the intended results you’re expecting elsewhere in the site. It has me wondering if there are better filters than pre_get_posts or potentially some sort of block setting that is available for adding extra post types to consider within a smaller scope.

    I don’t know for sure offhand though.

Viewing 1 replies (of 1 total)

The topic ‘Adding CPT to post widget blocks’ is closed to new replies.