elegantthemes / create-divi-extension

MIT License
185 stars 58 forks source link

Extending ET_Builder_Module_Featured_Posts_Slider to support custom post types #331

Open fadihania opened 4 years ago

fadihania commented 4 years ago

Problem Description

How can I extend the module class ET_Builder_Module_Featured_Posts_Slider to display custom post type instead of posts? I have tried extending the class with new slug and use that as shortcode.

class HB_Builder_Module_Featured_Custom_Posts_Slider extends ET_Builder_Module_Featured_Posts_Slider {

    function init() {
        parent::init();
        $this->template_name = 'module-featured-custom-posts-slider';
        $this->slug = 'hb_pb_featured_custom_posts_slider';
    }

    function _pre_wp_query( $args ) {
        $args = parent::_pre_wp_query( $args );

        $args['post_type'] = 'boating-product';

        return $args;
    }

}
new HB_Builder_Module_Featured_Custom_Posts_Slider;

Steps To Reproduce

  1. First I had errors complaining about undefined classes so I added those require statements

    require_once get_template_directory() . '/framework/functions.php';
    require_once get_template_directory() . '/includes/builder/feature/gutenberg/blocks/Layout.php';
    require_once get_template_directory() . '/includes/builder/core.php';
    require_once get_template_directory() . '/functions.php';
    require_once get_template_directory() . '/includes/builder/class-et-builder-element.php';
    require_once get_template_directory() . '/includes/modules.php';
  2. Then I used hb_pb_featured_custom_posts_slider as shortcode in my child theme template but it didn't work

ArcaneDiver commented 4 years ago

try to override the static method get_blog_posts then it should work, probably you should try to let the builder see you custom module.