admin管理员组文章数量:1123931
I already have a filter to show on archive pages the terms of the taxonomy "tipologia" according to the locale = 'de_DE'. I need a similar filter to show in german the same taxonomy terms inside a selector in the search box. I dont know how to replace some elements like get_the_archive_title Here is my filter:
add_filter('get_the_archive_title', function( $title_archive) {
$locale = get_locale();
if ('de_DE' == $locale ) {
$title_archive_de = get_term_meta( get_queried_object()->term_id, 'function_tipologia', true );
if ( ! empty( $title_archive_de )) {
return $title_archive_de;
} else {
return $title_archive;
}
} else {
return $title_archive;
}
}, 10, 2 );
My selector in the search box is:
$select = $wp_query->get('tipologia');
$select = '' == $select ? 0 : $select;
$taxonomy = wp_dropdown_categories([
'hierarchical' => false,
'name' => 'tipologia',
'taxonomy' => 'tipologia',
'selected' => $select,
'show_option_all' => esc_html__('Typology', 'sacconicase'),
'value_field' => 'slug',
'echo' => false
]);
I already have a filter to show on archive pages the terms of the taxonomy "tipologia" according to the locale = 'de_DE'. I need a similar filter to show in german the same taxonomy terms inside a selector in the search box. I dont know how to replace some elements like get_the_archive_title Here is my filter:
add_filter('get_the_archive_title', function( $title_archive) {
$locale = get_locale();
if ('de_DE' == $locale ) {
$title_archive_de = get_term_meta( get_queried_object()->term_id, 'function_tipologia', true );
if ( ! empty( $title_archive_de )) {
return $title_archive_de;
} else {
return $title_archive;
}
} else {
return $title_archive;
}
}, 10, 2 );
My selector in the search box is:
$select = $wp_query->get('tipologia');
$select = '' == $select ? 0 : $select;
$taxonomy = wp_dropdown_categories([
'hierarchical' => false,
'name' => 'tipologia',
'taxonomy' => 'tipologia',
'selected' => $select,
'show_option_all' => esc_html__('Typology', 'sacconicase'),
'value_field' => 'slug',
'echo' => false
]);
Share
Improve this question
asked Mar 21, 2024 at 7:21
Andrea SacconiAndrea Sacconi
797 bronze badges
1 Answer
Reset to default 1To achieve filtering according to the locale de_DE
for the taxonomy terms displayed in the search box selector, you can use a similar approach as your archive title filter.
add_filter('wp_dropdown_categories', function( $output, $args ) {
$locale = get_locale();
if ('de_DE' == $locale && $args['taxonomy'] == 'tipologia') {
// Modify output for German locale and 'tipologia' taxonomy
$terms = get_terms([
'taxonomy' => 'tipologia',
'hide_empty' => false,
]);
if ($terms && !is_wp_error($terms)) {
$output = '<select name="' . esc_attr($args['name']) . '">' . "\n";
$output .= '<option value="0">' . esc_html__('Typology', 'sacconicase') . '</option>' . "\n";
foreach ($terms as $term) {
$output .= '<option value="' . esc_attr($term->slug) . '">' . esc_html($term->name) . '</option>' . "\n";
}
$output .= '</select>' . "\n";
}
}
return $output;
}, 10, 2);
本文标签: phpFiltering according to the locale 39deDE39
版权声明:本文标题:php - Filtering according to the locale 'de_DE' 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736607593a1945366.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论