Answers for "unique post tags ni wordpress"

PHP
0

unique post tags ni wordpress

$post_ids = get_posts(
    array(
        'posts_per_page' => -1,
        'category_name'  => 'testing',
        'fields'         => 'ids', // Just get the ID's, save a hella lotta memory
    )
);

// Get and cache all post tags in one swoop
update_object_term_cache( $post_ids, 'post' );

// Build a unique index of tags for these posts
$tags = array();
foreach ( $post_ids as $post_id ) {
    if ( $post_tags = get_object_term_cache( $post_id, 'post_tag' ) ) {
        foreach ( $post_tags as $tag )
            $tags[ $tag->term_id ] = $tag;
    }   
}

// Show em!
foreach ( $tags as $tag ) {
    echo '<a href="' . get_term_link( $tag ) . '">' . $tag->name . '</a> ';
}
Posted by: Guest on September-22-2021

Browse Popular Code Answers by Language