Guest User

Untitled

a guest
Jan 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2. function valteri_pre_get_posts( $query ) {
  3. // Show only posts from 'blogi' category.
  4. if ( ! is_admin() && $query->is_main_query() && is_home() ) {
  5. // Get Finnish ID.
  6. $lang_fi = get_term_by( 'slug', 'fi', 'language' );
  7. $id_fi = $lang_fi->term_id;
  8.  
  9. // Get Swedish ID.
  10. $lang_sv = get_term_by( 'slug', 'sv', 'language' );
  11. $id_sv = $lang_sv->term_id;
  12.  
  13. // Show both languages.
  14. $tax_query = array(
  15. array(
  16. 'taxonomy' => 'language',
  17. 'field' => 'term_taxonomy_id',
  18. 'terms' => array( $id_fi, $id_sv ),
  19. ),
  20. );
  21. $query->set( 'tax_query', $tax_query );
  22.  
  23. // For some reason we need this that also Swedish blog page shows both languages.
  24. $query->set( 'lang', 'fi, sv' );
  25.  
  26. // Show only posts from these categories.
  27. $query->set( 'category__in', array( get_cat_ID( 'Blogi' ), get_cat_ID( 'Blog' ) ) );
  28. }
  29. }
  30. add_action( 'pre_get_posts', 'valteri_pre_get_posts' );
Add Comment
Please, Sign In to add comment