How to use Divi Blog Module for Custom Post Type

Divi Blog Module is a module in Divi where you can place your blog content anywhere in your WordPress website and in any format. Currently, it does not supports custom post type.

There are plugins to make it possible to use Divi Blog Module for Custom Post Type (CPT). One I found is Divi Custom Post Types, a specialist blog module for your CPTs. It cost $27.75 for a single site. I haven’t tried the plugin.

This how-to guide is to use Divi Blog Module for CPT without using such plugin. I used Custom Post Type UI plugin for creating CPT. I created Testimonial CPT with Testimonial category.

  1. Create Custom Post Type and check Categories (WP Core).
    Custom Post Type Categories WP Core
  2. Create and set Categories for your Custom Post Types.
  3. Add the code below to your child theme’s functions.php. Make sure to change your_cpt.
    add_action( 'pre_get_posts', function ( $q ) {
      if (!is_admin() && $q->is_category()) {
        $q->set( 'post_type', ['post', 'your_cpt'] );
      }
    });
    

    The code above is to include CPT’s category to the main query involving post type categories.

  4. Add blog module as usual and include only the category for your CPT.
    Divi Blog Module for Custom Post Type
5 comments
  1. Vikash
    Vikash
    January 20, 2020 at 6:47 am

    genius…Thanks for sharing brother.

    Reply
  2. hungeo
    hungeo
    April 22, 2020 at 6:41 am

    I do not know why, but it does not work for me.

    Reply
  3. Sean Callanan
    Sean Callanan
    May 10, 2020 at 2:33 am

    This didn’t work for me. I have added created/added categories to the custom posts when I added them as content, and I had already selected Categories (WP Core) as Taxonomies, I added my cpt to the php snippet and added it to functions.php, but when I add the Blog module and change from Post to my custom post type, the Categories selector in the module goes away just as before. Did I miss something?

    Reply
  4. antonello
    antonello
    May 18, 2020 at 6:04 pm

    Hello,
    I created a new custom post type … and categories … but when I select the new CPT … in the property editor I don’t see the categories.
    I tried with your code … but nothing.

    If I use a DIVI BLOG EXTRA plugin … I see all

    why? where I wrong?
    thanks
    Antonello

    Reply
  5. Mark Cunzolo
    Mark Cunzolo
    February 4, 2021 at 6:05 am

    This is a lifesaver and works like a charm! Everyone just needs to understand that when they use the blog module they have to leave the post type set as posts. Also, it won’t look like it works on the backend/frontend builder. However, it will load correctly on the true frontend browser.

    Reply
Leave a Reply

Your email address will not be published. Required fields are marked *