0

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
 ]);

1 Answer 1

1

To 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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.