Custom Post Types and Divi

Customizing Search Module

By default, the Divi Search Module only searches posts and pages, depending on the settings configured in the module itself. The code snippet below allows to retain those settings, but also add in the post types registered with Custom Post Type UI to be considered with the search as well.

function cptui_docs_include_cptui_in_divi_search_module( $query ) {
	if ( is_admin() || ! $query->is_main_query() ) {
		return;
	}

	if ( $query->is_search() ) {
		$post_types = [];
		$cptui_types = cptui_get_post_type_slugs();

		if ( isset( $_GET['et_pb_searchform_submit'] ) ) {
			// Respect the $_GET parameters set by Divi
			if ( ! isset( $_GET['et_pb_include_posts'] ) && ! isset( $_GET['et_pb_include_pages'] ) ) {
				$post_types = array( 'post' );
			}
			if ( isset( $_GET['et_pb_include_pages'] ) ) {
				$post_types = array( 'page' );
			}
			if ( isset( $_GET['et_pb_include_posts'] ) ) {
				$post_types[] = 'post';
			}
			// Merge in our own types as well.
			$post_types = array_merge( $post_types, $cptui_types );
		}
		$query->set( 'post_type', $post_types );
	}

	return $query;
// We set the priority to 11 so that our modifications run after Divi's
}
add_action( 'pre_get_posts', 'cptui_docs_include_cptui_in_divi_search_module', 11 );

Blog Module

At the time of this docs article, we have yet to find a workable way to get taxonomy term output included for listing of custom post types, without attempting to modify Divi core files.

Updated 3:24 pm