Performance: Taxonomy term management
This affects page load speed and interaction responsiveness when managing and displaying taxonomy terms in WordPress.
<?php $terms = wp_get_post_terms(get_the_ID(), 'category'); foreach($terms as $term) { echo esc_html($term->name); } ?>
<?php $terms = get_terms(array('taxonomy' => 'category', 'hide_empty' => false)); foreach($terms as $term) { echo $term->name; } ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetching all terms without filtering | High (many nodes) | Multiple reflows due to large DOM | High paint cost | [X] Bad |
| Fetching only post-related terms | Low (few nodes) | Single reflow | Low paint cost | [OK] Good |
| Loading all admin terms without pagination | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Loading admin terms with pagination | Moderate (limited nodes) | Few reflows | Moderate paint cost | [OK] Good |
wp_insert_term(). $terms = get_terms(['taxonomy' => 'genre', 'hide_empty' => false]);
foreach ($terms as $term) {
echo $term->name . ', ';
}wp_update_term(123, 'category', ['name' => 'New Name']);
term_exists('Adventure', 'book_genre') to verify if the term is already present.wp_insert_term('Adventure', 'book_genre') to add it.Pass the test and this pattern moves unknown