Posts Module for Beaver Builder allows you to display any post type content from your WordPress site. Per module you select one post type content. In this tutorial I shall show how you will display the multiple post types content on single Posts Module. For example, I created a custom post type “event”. On my home page I shall display the content of two post types: post & event.
I drag&drop the BB Post-Grid module on my home page. When I am selecting the post type into the module settings form, I can’t select two post types from Post Type drop down box under Content Tab -> Custom Query section.
So I check the fl-builder-loop.php file and get a filter fl_builder_loop_query for custom query source. Later I add this small PHP codes into the functions.php of my theme.
add_filter( 'fl_builder_loop_query', 'paulc_post_module_loop', 10, 2); function paulc_post_module_loop( $query, $settings ) { if( ! is_home() ) return $query; $query_args = $query->query_vars; $query_args['post_type'] = array( 'post', 'event' ); $query = new WP_Query( $query_args ); return $query; }
Line no 6-7: Doing nothing if it is not home page. is_home() conditional tag is checking it. There have more conditional tags like is_front_page(), is_category(), is_archive() etc.
Line no 9: Getting the defaults query args
Line no 11: Editing the post_type value. Passing the two post types as array variable
Line no 13: Creating the new query object
Line no 15: Returning this new query object