Support

Account

Home Forums General Issues Filtering issues which remove images and filters on page Reply To: Filtering issues which remove images and filters on page

  • Ok so I’ve managed to get my images pulling through even when filtering which was a simple fix of changing the Return Value of the “film_poster” field to Image ID. It now works when I’m viewing the standard /films page as well as if I send a query (e.g. /films/?film_genre=Action).

    However, I’m still having problems with the filters disappearing when the query is sent (e.g. apexcinemas.andrewcourtney.co.uk/films/?film_genre=Action) – any ideas?

    Below is the code I have running in the functions.php page, taken from the ACF tutorial I mentioned before 🙂

    // filter film genre
    add_action(‘pre_get_posts’, ‘my_pre_get_posts’);

    function my_pre_get_posts($query){
    // validate
    if(is_admin()){
    return;
    }

    // Get original meta query
    $meta_query[] = $query->get(‘meta_query’);

    // allow the url to alter the query
    // e.g. ?film_genre=comedy
    if(isset($_GET[‘film_genre’])){

    $film_genre = explode(‘,’, $_GET[‘film_genre’]);

    // Add our meta query to the original meta queries
    $meta_query[] = array(
    ‘key’ => ‘film_genre’,
    ‘value’ => $_GET[‘film_genre’],
    ‘compare’ => ‘IN’,
    );
    }

    // update the meta query arguments
    $query->set(‘meta_query’, $meta_query);

    // always return
    return;
    }

    Thanks in advance!