First of all, I've enable the legacy view.
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
I've created the following view that should display the total count using the shortcode:
- hidden link
[wpv-found-count]
Now, we can reuse the same view for different fields and values, having said that we are filtering the view results (in your case its total count) using view's shortcode attribute. For example"
[wpv-view name="View A" sector="sector-a"]
[wpv-view name="View A" sector="sector-b"]
For that - I've added the following vieww's filter hook "wpv_filter_query" to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> hidden link
add_filter('wpv_filter_query','func_show_total_checkbox_count_shortcode_argument', 99, 3);
function func_show_total_checkbox_count_shortcode_argument($query_args, $view_settings,$view_id) {
// Check if it's the correct View
if ($view_id == 2108) {
global $WP_Views;
$field_slug = $field_value = '';
if(isset($WP_Views->view_shortcode_attributes[0]['field_slug'])){
$field_slug = $WP_Views->view_shortcode_attributes[0]['field_slug'];
}
if(isset($WP_Views->view_shortcode_attributes[0]['field_value'])){
$field_value = $WP_Views->view_shortcode_attributes[0]['field_value'];
}
$target_field = 'wpcf-'.$field_slug;
if(!empty($field_value) and !empty($field_value)) {
$query_args['meta_query'][] = array(
'key' => $target_field,
'value' => $field_value,
'type' => 'NUMERIC',
'compare' => '='
);
}else if(empty($field_value)){
$query_args['meta_query'][] = array(
'key' => $target_field,
'compare' => 'NOT EXISTS'
);
}
}
return $query_args;
}
I've created the following test page and added the view's shortcode as given under with view's shortcode argument "field_slug" and "field_value":
- hidden link
Бзвп - YES: <span> [wpv-view name="show-total-count" cached="off" field_slug='potrebuye-bzvp' field_value='1'] </span>
Бзвп - NO: <span> [wpv-view name="show-total-count" cached="off" field_slug='potrebuye-bzvp'] </span>
ФП- YES: <span> [wpv-view name="show-total-count" cached="off" field_slug='potrebuye-fp' field_value='1'] </span>
ФП- NO: <span> [wpv-view name="show-total-count" cached="off" field_slug='potrebuye-fp'] </span>
Where:
- we are passing the custom field slug to view's shortcode attribute name "field_slug"
- we are passing the custom field slug to view's shortcode attribute name "field_value"
As you can see it displays correct total post count on frontend:
- hidden link
You can add more views like this for your other field values.
For exaple:
- To display Yes count:
[wpv-view name="show-total-count" cached="off" field_slug='your-field-slug' field_value="your-field-value"]
- To display NO count:
[wpv-view name="show-total-count" cached="off" field_slug='your-field-slug']
More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-found-count
I hope all above information will help you to resolve your issuel