Support

Account

Home Forums Front-end Issues ACF Ajax filter not working

Unread

ACF Ajax filter not working

  • I have created an ajax filter and it’s not showing the results correctly.

    When you click more than one checkbox it can’t find anything despite there should be something there.

    I think my array is too inside itself, but can’t work out how to “unpick” it….

    $exp_query[] = '';
    if(!empty($experimentChoices)){
        foreach($experimentChoices as $Key=>$Value){
            if(count($Value)){
                foreach ($Value as $Inkey => $Invalue) {
                    $exp_query[] = array( 
                        'key' => $Key, 
                        'value' => $Invalue, 
                        'compare' => '=' 
                    );
                }
            }
        }
    }
    
    $test = array(
        'relation' => 'OR',
        $exp_query,
    );
    
    $args = array(
        'post_type' => 'downloads',
        'meta_query' => array(
            'relation' => 'AND',
            $test,          
        ),
    );

    So it outputs as;

    FOREACH (Broken)
    Array ( [relation] => OR [0] => Array ( [0] => [1] => Array ( [key] => experiment_type [value] => abuse-dependence [compare] => = ) [2] => Array ( [key] => experiment_type [value] => diabetes [compare] => = ) ) )

    WRITTEN CODE (Working)
    Array ( [relation] => OR [0] => Array ( [key] => experiment_type [value] => abuse-dependence [compare] => = ) [1] => Array ( [key] => experiment_type [value] => diabetes [compare] => = )

    Any help would be great thanks.

Viewing 1 post (of 1 total)

The topic ‘ACF Ajax filter not working’ is closed to new replies.