Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function valteri_pre_get_posts( $query ) {
- // Show only posts from 'blogi' category.
- if ( ! is_admin() && $query->is_main_query() && is_home() ) {
- // Get Finnish ID.
- $lang_fi = get_term_by( 'slug', 'fi', 'language' );
- $id_fi = $lang_fi->term_id;
- // Get Swedish ID.
- $lang_sv = get_term_by( 'slug', 'sv', 'language' );
- $id_sv = $lang_sv->term_id;
- // Show both languages.
- $tax_query = array(
- array(
- 'taxonomy' => 'language',
- 'field' => 'term_taxonomy_id',
- 'terms' => array( $id_fi, $id_sv ),
- ),
- );
- $query->set( 'tax_query', $tax_query );
- // For some reason we need this that also Swedish blog page shows both languages.
- $query->set( 'lang', 'fi, sv' );
- // Show only posts from these categories.
- $query->set( 'category__in', array( get_cat_ID( 'Blogi' ), get_cat_ID( 'Blog' ) ) );
- }
- }
- add_action( 'pre_get_posts', 'valteri_pre_get_posts' );
Add Comment
Please, Sign In to add comment