나는 여기에있는 누군가가 나를 도울 수있는 꽤 발전된 문제가 있습니다. 나는 다음과 같습니다의 '제품'Wordpress : 카테고리별로 필터링 된 사용자 정의 분류 유형이있는 사용자 정의 게시물 유형의 get_categories
사용자 정의 분류의
사용자 정의 포스트 유형 '브랜드'
'카테고리'각각의 '제품'의 표준 분류는 태그입니다
&
아카이브 : '브랜드'와 부모와 자식 카테고리
에 배치 나는 다음을 수행해야합니다. PHP 페이지에는 '브랜드'분류 체계가있는 '제품'이있는 '카테고리'가 모두 표시되며 '브랜드'분류의 가치가 있습니다. 이것은 다음 함수를 사용하는 @MikeSchinkel
$term = get_query_var('term');
$brand = get_term_by('slug',$term,'brands'); // This here just to illustrate
$categories = get_cross_referenced_terms(array(
'post_type' => 'Products',
'taxonomy' => 'category',
'related_taxonomy' => 'brands',
'term_id' => $brand->term_id
));
덕분에 아래의 기능이 잘 작동 :
// query to get categories for a specific tag
function get_cross_referenced_terms($args) {
global $wpdb;
$args = wp_parse_args($args,array(
'post_type' => 'Products',
'taxonomy' => 'category',
'related_taxonomy' => 'brands',
'term_id' => 0,
));
extract($args);
$sql = <<<SQL
SELECT DISTINCT
{$wpdb->terms}.*,
COUNT(*) AS post_count
FROM
{$wpdb->terms}
INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->terms}.term_id={$wpdb->term_taxonomy}.term_id
INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id={$wpdb->term_relationships}.term_taxonomy_id
INNER JOIN {$wpdb->posts} ON {$wpdb->term_relationships}.object_id={$wpdb->posts}.ID
INNER JOIN {$wpdb->term_relationships} related_relationship ON {$wpdb->posts}.ID=related_relationship.object_id
INNER JOIN {$wpdb->term_taxonomy} related_term_taxonomy ON related_relationship.term_taxonomy_id=related_term_taxonomy.term_taxonomy_id
INNER JOIN {$wpdb->terms} related_terms ON related_term_taxonomy.term_id=related_terms.term_id
WHERE 1=1
AND related_terms.term_id<>{$wpdb->terms}.term_id
AND {$wpdb->posts}.post_type='%s'
AND {$wpdb->term_taxonomy}.taxonomy='%s'
AND related_term_taxonomy.taxonomy='%s'
AND related_terms.term_id=%d
AND {$wpdb->term_taxonomy}.parent=0
GROUP BY
{$wpdb->terms}.term_id
SQL;
$sql = $wpdb->prepare($sql,$post_type,$taxonomy,$related_taxonomy,$term_id);
$terms = $wpdb->get_results($sql);
return $terms;
}
이 지정된 브랜드에 대한 모든 범주를 표시하고 현장에서 작동합니다. 하지만 이제 카테고리 페이지에 'child_of'를 설정할 수 있어야합니다. 그래서 내가 추가 할 필요가있는 것은 카테고리 ID를 쿼리하거나 카테고리 부모를 지정하는 것입니다. 뭔가 같이 : 내 리그에서
AND {$wpdb->term_taxonomy}.parent=0
하지만 조금 :
'child_of' => $parent_category
나는 내가 여기에 데이터베이스 쿼리에 추가 할 수있는 일이 될 것 같아요! 아무도 나를 도와 줄 수 없다면 나는 매우 감사 할 것입니다! 감사합니다
데이브