WPML
상태
해결됨
유형
버그
보고 대상
WPML Multilingual CMS 3.3.6
해결된 버전
3.3.7

문제 개요

특정 사용자 정의 글 유형의 아카이브 페이지에서 글 표시를 필터링하기 위해 wp_get_archives을(를) 사용하고 post_type 인수를 지정하는 방법이 작동하지 않습니다.

이 문제는 WordPress 4.4 릴리스에서 발생한 점을 참고하세요.

예시:

슬러그가 “news”인 사용자 정의 글 유형이 있고, 테마(archive-news.php)에 해당 사용자 정의 글 유형을 위한 사용자 정의 아카이브 템플릿을 생성한다고 가정해 보겠습니다.

해당 파일에서 아카이브를 렌더링하기 위해 다음 코드를 사용할 수 있습니다.

$my_archives=wp_get_archives(array(

	'type'=>'alpha', 

	'show_post_count'=>true, 

	'limit'=>20, 

	'post_type'=>'news', 

	'format'=>'html' 

));

print_r($my_archives);

현재 이 코드는 작동하지 않으며 글이 표시되지 않습니다.

임시 해결 방법

다음 단계를 진행하기 전에 사이트의 파일을 편집한다는 점을 숙지하세요. 이 작업을 올바르게 수행하지 않으면 웹사이트가 작동을 멈출 수 있습니다.

먼저 안전한 환경에서 이 작업을 테스트하거나, 진행하기 전에 최소한 웹사이트의 전체 백업을 실행하는 것을 강력히 권장합니다.


  1. sitepress-multilingual-cms\sitepress.class.php 파일을 여세요.

  2. 219번째 줄로 이동하세요.

    • 변경 전:
      add_filter( 'getarchives_join', array( $this, 'getarchives_join' ) );

    • 변경 후:
      add_filter( 'getarchives_join', array( $this, 'getarchives_join' ), 10, 2 );

  3. 3685번째 줄로 이동하세요.

    • 변경 전:
      function getarchives_join( $join ) {
      	return $join . " JOIN {$this->wpdb->prefix}icl_translations t ON t.element_id = {$this->wpdb->posts}.ID AND t.element_type='post_post'";
      }

    • 변경 후:
      function getarchives_join( $join, $args ) {
      	$post_type = array_key_exists( 'post_type', $args ) ? $args['post_type'] : 'post';
      	$post_type = esc_sql( $post_type );
      
      	return $join . " JOIN {$this->wpdb->prefix}icl_translations t ON t.element_id = {$this->wpdb->posts}.ID AND t.element_type='post_" . $post_type . "'";
      }

모든 알려진 문제