How to make a selection of tags of all posts, excluding all repetitions? I need to display 1 or more search tips, and now it is displayed equal to the number of posts. How to fix? Now the code looks like this:
function theme_enqueue_scripts() { // Enqueue jQuery UI and autocomplete wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-autocomplete' ); } add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' ); function theme_autocomplete_js() { $args = array( 'post_type' => 'portfolio', 'post_status' => 'publish', 'posts_per_page' => -1 // all posts ); $posts = get_posts( $args ); if( $posts ) : foreach( $posts as $k => $post ) { $source[$k]['ID'] = $post->ID; $tags = wp_get_post_terms($post->ID, 'portfolio_entries'); foreach($tags as $tag){ $tags_array[] = $tag->name; //$tags_array = array_unique($tags_array); } $tags_array = array_unique($tags_array, SORT_REGULAR); $comma_separated_tags = implode( ', ' , $tags_array); $source[$k]['label'] = $comma_separated_tags;//$post->post_title; // The name of the post $source[$k]['permalink'] = get_permalink( $post->ID ); } ?> <script type="text/javascript"> jQuery(document).ready(function($){ var posts = <?php echo json_encode( array_values( $source ) ); ?>; jQuery( '#s' ).autocomplete({ source: posts, minLength: 2, select: function(event, ui) { var permalink = ui.item.permalink; // Get permalink from the datasource window.location.replace(permalink); } }); }); </script> <?php endif; } add_action( 'wp_footer', 'theme_autocomplete_js' ); Here is the output: 
Live to try here .
