分類法とユーザーの役割を組み合わせて、税金の「犬」のすべての用語と、各用語「犬」について、ユーザー プロファイルにリンクされているすべての「色」のリストをリストしています。例:
- ユーザー 1 は、メタ「犬: ゴールデンレトリバー」と「色: 黄」をプロファイルに保存しています。
- ユーザー 2 は、メタ「犬: ゴールデンレトリバー」と「色: 黒」をプロファイルに保存しています。
- ユーザー 3 は、メタ「犬: ゴールデンレトリバー」と「色: 黒」をプロファイルに保存しています。
以下の 3 つのタグの見出しは、「用語名」を吐き出します = この場合は「犬」になります。犬の下には、ユーザー メタを介してこの犬にリンクされている「色」のリスト (IE、黄、黒) があるはずです。重要なことは、"Black" が 2 回ではなく 1 回だけ表示されることです。重複を削除しようとしていますが、エラーが発生しています。
編集済み: エラーは解消されました。ただし、現在、echo $array は「黒」のみをエコーし、「黄色」やその他の色はエコーしません。
何かご意見は?
<?php $terms = get_terms('dogs');
$count = count($terms);
if ( $count > 0 ){ foreach ( $terms as $term ) { ?>
<h3><?php echo $term->name; ?></h3> // Show different "dog" type names
<div class="listed_dogs_color_names">
// Now search all editor and contributor user profiles for "dog" and "color" user_meta. Color and dog are both taxonomies that are used both with posts and users (user meta)
// If matches with the "dog" above, list "color" underneath "dog name" in <h3></h3> above.
<?php
$term_parent = $term->parent;
$term_slug = $term->slug;
$editor_query = new WP_User_Query(
array(
'role' => 'editor',
'meta_key' => $term_parent,
'meta_compare' => '=',
'meta_value' => $term_slug,
)
);
$editors = $editor_query->get_results();
$contributor_query = new WP_User_Query(
array(
'role' => 'contributor',
'meta_key' => $term_parent,
'meta_compare' => '=',
'meta_value' => $term_slug,
)
);
$contribs = $contributor_query->get_results();
$users = array_merge( $contribs, $editors );
?>
<?php
$array = array(); // initialize as empty array ?>
<?php if (!empty($users)) {?>
<?php foreach ($users as $user) :
$b = $user->color;
$color = explode("\n", $b);
$array[] = $color[0];
?>
<?php endforeach; ?>
<?php $array = array_unique($array); ?>
<?php
echo "<li>";
echo $array[0];
echo "</li>";
?>
<?php } ?>
</div><!--close-->
<?php }?>
<?php }?>