View query filter for whether an image custom field has content
Started by: Anthony
in: Toolset Professional Support
Quick solution available
Problem:
The issue here is that the user wanted to filter their view with a query filter to not include posts where the image custom field is empty.
Solution:
This can be done with the hook below.
//Return only products with banner images
add_filter( 'wpv_filter_query', 'filter_empty_banners', 99, 3 );
function filter_empty_banners( $query_args,$view_settings ,$view_id ) {
if ( $view_id == 44576) {
$query_args['meta_query'] = array(
array(
'key' => 'wpcf-banner',
'value' => '',
'compare' => '!='
)
);
}
return $query_args;
}
Add the above to your Toolset custom code section in Toolset -> Custom Code and activate it. You will need to change the 44576 to your view's id as well as the wpcf-banner to the slug of your image field keeping the wpcf- prefix.
2
5
4 years, 12 months ago
Anthony