I have a list of categories that are made up of multiple recurring (italian) words, like this:
- racconti sulla vita
- racconti di passione
- racconti sui pensieri
- racconti motivazionali
- ...
What I need to do is remove from the list all the recurring words (racconti, sulla, di, sui, sul, etc.) and then order the rest from A to Z.
The result is really weird: the total number of categories is 42 and I get the first 31 results in the right order (in this case from B to V). From 32nd item, the list starts again in the right order (from A to S).
It's like if the list was split in 2 parts.
This is my code:
$terms_tipologia = get_terms( 'tipologia', array( 'hide_empty' => true ) );
foreach ( $terms_tipologia as $tipologia ) :
$words = array("racconti", "sul", "sull'", "sulla", "sulle", "sullo", "sui", "di");
$pattern = '/\b(?:' . join('|', $words) . ')\b/i';
$term_name = preg_replace($pattern, '', $tipologia->name);
$term_link = get_term_link($tipologia);
$reorder[$term_link] = $term_name;
endforeach;
asort($reorder);
foreach ( $reorder as $link => $nome ) :
echo '<li><a href="'.esc_url( $link ).'">' . $nome . '</a></li>';
endforeach;