Skip Navigation

[Resolved] Filter “if field has value”

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 20 replies, has 1 voice.

Last updated by arnoldd 9 hours, 21 minutes ago.

Assisted by: Minesh.

Author
Posts
#2868476

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've activated the filter.

#2868491

It simply does not work now.

If all is empty and i select : Utrecht nothing happens. Why? there are two results: Leppers and Van Dam.
But if i check also "nieuwbouwactie" only Leppers shows. Thats not right.

The filter "provincie" does not work right now.

#2868547

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please check now: hidden link

It should work now. I've adjusted the code to custom code section as given under:

add_filter('wpv_filter_query', 'func_filter_posts_by_checkbox', 99, 3);  
function func_filter_posts_by_checkbox($query_args, $view_settings, $view_id) {
   
if($view_id == 1227 and (defined( 'DOING_AJAX') and DOING_AJAX) )  {
   
  
  		$is_checked = false;
        foreach($_POST['search']['dps_general'] as $k=>$v):
                if(isset($v['name']) and $v['name'] == 'wpv-wpcf-nieuwbouwactie-titel[]' and  $v['value'] == '1'){
                     $is_checked = true;            
                }
  
                           
        endforeach;

         $meta_query = $query_args['meta_query'];
    	 
  
       $hook_meta_query = array();
  
        foreach($meta_query as $k=>$v):
            if(isset($v['key']) and $v['key']=='wpcf-nieuwbouwactie-titel' and $is_checked){
                   $found_index = $k; 
              	   
                   $hook_meta_query = array('relation'=>'OR',
                                            
                     						array('relation'=>'AND',
                     								array('key'=>'wpcf-nieuwbouwactie-titel',
                                              				'compare'=>'EXISTS'),
                     								array('key'=>'wpcf-nieuwbouwactie-titel',
                                               				'value'=>'',
                                               				'compare'=>"!=")
                                            
                                            )
                                        );
                   break;

              }
  		endforeach;
  
  		if(!empty($hook_meta_query)){
          	
          	$query_args['meta_query'][$found_index] = $hook_meta_query;
          	
          
          
        }
        
  
          	
     	
   }   
return $query_args;
}

#2868548

Goodmorning Minesh (over here),

Almost 🙂 If the "nieuwbouwactie" checkbox would work it would be perfect. Now this does nothing.

#2868550

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked both filters "Provincie" and "Nieuwbouwactie" both works as expected:
- hidden link

Please make sure you should refresh the page and delete the cache.

#2868551

Wow. Thats it! Thank you very much!