Home Forums General Issues Trouble filter query on acf checkbox value and $paged Reply To: Trouble filter query on acf checkbox value and $paged

  • I tried that. It doesn’t work. It still outputs all items in the custom post type instead of only the items that meet that particular condition.

    btw, the field group is a checkbox – not yes/no. They have specific selections: “speight” & “embassy”. I need to only display items that have “speight” selected.

    I can get the right plans to display properly by using the following code, but it doesn’t fix the $paged issue (it still shows the count of *all* items in that post-type instead of just the ones in my query args.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $total_posts = $wp_query->found_posts;
    $start_post = ($paged - 1) * $posts_per_page + 1;
    $end_post = min($start_post + $posts_per_page - 1, $total_posts);
    $args = array(
        'post_type' => 'speight_home_plans',
        'orderby'=> 'title',
        'order' => 'ASC',
        'paged' => $paged
    $query = new WP_Query( $args );
    if ($query->have_posts()) :
    while ( have_posts() ) : the_post();
    $selected = get_field('display_where');
    if( in_array('speight', $selected) ) {
        get_template_part( 'template-parts/plan-archive-loop', get_post_format() );

    I’m wondering if the issue is that the ACF field isn’t somehow specified before the arg the same way it’s called in the loop itself? I mean, if all I’m telling it is “display_where” (the name of the field within the post type), without doing the whole get_field(‘display_where’) part of it, does it know how to see it? but I’ve tried calling it that way and it doesn’t make a difference.