WordPress Gallery is not displaying

Waited a lot but couldn’t find an answer… I found the issue but doesn’t know how to resolve it. But fortunately there is a way around it.

I have been using wordpress’s pre_get_posts hook to set a tax_query which looks like this:

add_action( 'pre_get_posts', 'homeInjector' );

function homeInjector( $query ) {

        if ( $query->is_home() ) {

            $issues = get_terms( array(
                'taxonomy' => 'issues'
            ) );

            if ( isset( $_POST['issue'] ) ) {
                $term = $_POST['issue'];
            } else {
                $term = $issues[0]->slug;
            }


            $arg = array(
                array(
                    'taxonomy' => 'issues',
                    'terms'    => $term,
                    'field'    => 'slug'
                )
            );

            $query->set( 'tax_query', $arg );

        }

but if I use same code in index.php with new WP_Query object it works!

$issues = get_terms( array(
    'taxonomy' => 'issues'
) );

if ( isset( $_POST['issue'] ) ) {
    $term = $_POST['issue'];
} else {
    $term = $issues[0]->slug;
}

$qry = new WP_Query( array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'issues',
            'terms'    => $term,
            'field'    => 'slug'
        )
    )
) );

Don’t know why but it works…

But still I’ll wait for the appropriate answer because mine is just a way around to help me and others 🙂