Sacconi69

prova array tassonomia in search box

Mar 1st, 2024
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //PROVA CERVELLONE STACKEXCHANGE
  2.  
  3. // Retrieve all terms for 'tipologia' taxonomy
  4. $tipologia_terms = get_terms(array(
  5. 'taxonomy' => 'tipologia',
  6. 'hide_empty' => false, // Include empty terms as well
  7. ));
  8.  
  9. // Initialize an empty array to store term translations
  10. $names_trans = array();
  11.  
  12. // Iterate over each term and add its translation to the array
  13. foreach ($tipologia_terms as $term) {
  14. $names_trans[$term->term_id] = __($term->Apartment, 'sacconicase');
  15. }
  16.  
  17. // Now you have your $names_trans array with translations of tipologia terms
  18.  
  19. // Now in your wp_dropdown_categories call, you can use the $names_trans array to translate the terms
  20.  
  21. $select = $wp_query->get('tipologia');
  22. $select = '' == $select ? 0 : $select;
  23.  
  24. $taxonomy = wp_dropdown_categories([
  25. 'hierarchical' => false,
  26. 'name' => 'tipologia',
  27. 'taxonomy' => 'tipologia',
  28. 'selected' => $select,
  29. 'show_option_all' => esc_html__('Typology', 'sacconicase'),
  30. 'value_field' => 'slug',
  31. 'echo' => false,
  32. 'show_option_all' => esc_html__('Typology', 'sacconicase'),
  33. 'walker' => new Custom_Taxonomy_Dropdown_Walker($names_trans), // Pass $names_trans to custom walker
  34. ]);
  35.  
  36. //FINE PROVA
  37.  
Advertisement
Add Comment
Please, Sign In to add comment