Skip to content

Instantly share code, notes, and snippets.

@samikeijonen
Last active December 10, 2017 20:43
Show Gist options
  • Save samikeijonen/c3c64ec2503749e7d578ca1e0d744706 to your computer and use it in GitHub Desktop.
Save samikeijonen/c3c64ec2503749e7d578ca1e0d744706 to your computer and use it in GitHub Desktop.
Translate only terms from taxonomy "contact_area" when filterin "contact" post type posts. Posts are not translates at all because they only have name, email, and phone number.
<?php
$terms = get_terms( array(
'taxonomy' => 'contact_area',
'hide_empty' => false, // Other than default language don't have any posts.
'orderby' => 'name',
'lang' => function_exists( 'pll_current_language' ) ? pll_current_language() : '',
) );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) :
foreach ( $terms as $term ) :
// Always use default language ID because we don't have translations for other languages.
$term_default_lan_id = function_exists( 'pll_get_term' ) ? pll_get_term( $term->term_id, pll_default_language() ) : $term->term_id;
echo '<option value="' . $term_default_lan_id . '"' . selected( $term->slug, 'hallinto', false ) . '>' . $term->name . '</option>';
endforeach;
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment