• Riccardo91

    (@alopex91)


    Why this code in functions.php has this strange side effect of switching the menu to the mobile version in not-home pages ?

    function my_blog_category( $query ) {
     if ( $query->is_home() && !is_front_page() || is_archive()) {
     $query->set( 'cat', '6');
     }
    }
    add_action( 'pre_get_posts', 'my_blog_category' );

    This code works, the problem is its side effect of completely changing the nav with the mobile version that obviously at desktop width has “display:none;” so in the end I have the right posts query but no primary menu. This is odd.

    Theme used: Eightmedi lite

    • This topic was modified 7 years ago by Riccardo91.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Pioneer Web Design

    (@swansonphotos)

    and/not/or might cause some PHP issues.

    Thread Starter Riccardo91

    (@alopex91)

    So how should I change the code?
    I tried to group something, the code still works but same side effect.

    function my_blog_category( $query ) {
        if ( $query->is_home() && ( !is_front_page() || is_archive() ) ) {
            $query->set( 'cat', '6');
        }
    }
    add_action( 'pre_get_posts', 'my_blog_category' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Strange side effect of a PHP post query code’ is closed to new replies.