unique post tags ni wordpress

Solutions on MaxInterview for unique post tags ni wordpress by the best coders in the world

showing results for - "unique post tags ni wordpress"
Solène
11 Jan 2017
1$post_ids = get_posts(
2    array(
3        'posts_per_page' => -1,
4        'category_name'  => 'testing',
5        'fields'         => 'ids', // Just get the ID's, save a hella lotta memory
6    )
7);
8
9// Get and cache all post tags in one swoop
10update_object_term_cache( $post_ids, 'post' );
11
12// Build a unique index of tags for these posts
13$tags = array();
14foreach ( $post_ids as $post_id ) {
15    if ( $post_tags = get_object_term_cache( $post_id, 'post_tag' ) ) {
16        foreach ( $post_tags as $tag )
17            $tags[ $tag->term_id ] = $tag;
18    }   
19}
20
21// Show em!
22foreach ( $tags as $tag ) {
23    echo '<a href="' . get_term_link( $tag ) . '">' . $tag->name . '</a> ';
24}
25
similar questions
queries leading to this page
unique post tags ni wordpress