Problem: I would like to use get_view_query_results to find the number of results for a View, filtered by a shortcode attribute.
Solution:
The 4th argument of the get_view_query_results function takes an array of arguments, like those you would add as View shortcode attributes. In order to pass that into the get_view_query_results function, you probably need to add it as an attribute in your custom shortcode like this:
function get_students_count( $atts ) { $atts = shortcode_atts( [ 'wpvprchildof' => 0 ], $atts ); $args = array( 'wpvprchildof'=> $atts['wpvprchildof'] ); $filtered_posts = get_view_query_results(258, null, null, $args); return count($filtered_posts); } add_shortcode( 'wpv-students-count', 'get_students_count' );
Then use the shortcode like this:
[wpv-students-count wpvprchildof='[wpv-post-id]'][/wpv-students-count]
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 2 voices.
Last updated by vimalS 6 years ago.
Assisted by: Christian Cox.