I've got a custom wordpress query of a custom post type with a custom taxonomy. I'm trying to echo out a list of linked terms (tags). For the duplicated terms, I'd like to show the count of duplicated terms. Unfortunately I can't figure out how to count the items & store the info before I call array_unique(). Any suggestions would be greatly appreciated. Here's my Wordpress Query:
//Begin Custom Query
$args=array(
'post_type' => 'gw_activity',
'post_status' => 'publish',
'orderby' => 'date',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'activity_category',
'value' => 'mindful_life',
'compare' => '='
)
),
'posts_per_page' => -1
);
$my_query = null;
$my_query = new WP_Query($args);
Here's how I'm building my array of the terms:
if( $my_query->have_posts() ) {
$all_terms = array();
$all_slugs = array();
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $terms = wp_get_post_terms( $my_query->post->ID, array( 'gw_activity_tag' ) ); ?>
<?php
foreach ( $terms as $term ) {
$all_terms[] = $term->name; // Used for Display Purposes
$all_slugs[] = $term->slug; // Used in the Final Permalink of the term
}
?>
<?php endwhile; }
wp_reset_query();
// End Custom Query
Here's how I'm making the unique array of terms & slugs:
$unique_terms = array_unique( $all_terms ); // Eliminate Duplicate Terms
$unique_slugs = array_unique( $all_slugs ); // Eliminate Duplicate Slugs
$final_term_list = array(); //Build Array of Unique Terms
$i = 0;
foreach ($unique_terms as $value) { // Build a Unique Array of Terms
$final_term_list[$i] = $value;
$i++;
}
$final_slug_list = array(); //Build Array of Unique Slugs
$s = 0;
foreach ($unique_slugs as $slug_value) { // Build a Unique Array of Slugs
$final_slug_list[$s] = $slug_value;
$s++;
}
Here's how I'm outputting the data
$fl = 0; //Create a counter to index the array
foreach($final_slug_list as $final_slug) {
echo '<a href="'. get_bloginfo('url') .'/activity-category/'. $final_slug_list[$fl] .'/">'.$final_term_list[$fl].'</a>';
$fl++;
} // End foreach