콘텐츠로 건너뛰기

Divi테마 검색 결과에서 글, 제품 및 기타 게시물 유형을 활성화하는 방법

Divi테마를 사용해 워드프레스에서 쇼핑몰을 운영 중인 경우, 검색 기능에서 블로그 글과 WooCommerce의 상품이 함께 검색되지 않고 글만 검색 결과에 출력됩니다.

이때 Divi테마 검색 결과에서 글, 제품 및 기타 게시물 유형을 활성화하는 방법을 소개합니다.

Divi테마 검색 설정

Divi테마의 검색 설정은 기본적으로 게시물 및 페이지만 검색이 됩니다. 그러므로 WooCommerce에 등록된 상품과 같은 다른 게시물 유형을 활성화하려면, 사용자 지정 PHP 코드를 추가해야 합니다.

가장 먼저 필요한 것은 Divi 업데이트 후에도 변경 사항이 지속되도록 Divi 자식 테마를 만드는 것입니다. 여기 당신이 따를 수 있는 어린이 테마를 만드는 방법에 대한 튜토리얼이 있습니다.

테마파일 편집기

Screenshot

functions.php 수정

Once you created the child theme, place the following code to the bottom of the /functions.php  file of your child theme:

function custom_remove_default_et_pb_custom_search() {
remove_action( 'pre_get_posts', 'et_pb_custom_search' );
add_action( 'pre_get_posts', 'custom_et_pb_custom_search' );
}
add_action( 'wp_loaded', 'custom_remove_default_et_pb_custom_search' );

function custom_et_pb_custom_search( $query = false ) {
if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {
return;
}

if ( isset( $_GET['et_pb_searchform_submit'] ) ) {
$postTypes = array();

if ( ! isset($_GET['et_pb_include_posts'] ) && ! isset( $_GET['et_pb_include_pages'] ) ) {
$postTypes = array( 'post' );
}

if ( isset( $_GET['et_pb_include_pages'] ) ) {
$postTypes = array( 'page' );
}

if ( isset( $_GET['et_pb_include_posts'] ) ) {
$postTypes[] = 'post';
}

/* BEGIN Add custom post types */
$postTypes[] = 'product';
/* END Add custom post types */

$query->set( 'post_type', $postTypes );

if ( ! empty( $_GET['et_pb_search_cat'] ) ) {
$categories_array = explode( ',', $_GET['et_pb_search_cat'] );
$query->set( 'category__not_in', $categories_array );
}

if ( isset( $_GET['et-posts-count'] ) ) {
$query->set( 'posts_per_page', (int) $_GET['et-posts-count'] );
}
}
}

검색결과에 다른 사용자 지정 게시물 유형을 포함해야하는 경우

코드의 이 부분을 편집

/* BEGIN Add custom post types */
$postTypes[] = 'product';
/* END Add custom post types */

어, 프로젝트 포스트 유형을 포함하려면 다음과 같은 코드를 변경하세요:

/* BEGIN Add custom post types */
$postTypes[] = 'product';
$postTypes[] = 'project';
/* END Add custom post types */

How to enable Products and other post types in Divi’s Search Module

Subscribe
Notify of
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x