Problem: I need to know if a View will have any results
Solution: A custom shortcode can be used to count the results of any View:
add_shortcode( 'ts_view_has_results', 'ts_view_has_results_func'); function ts_view_has_results_func($atts) { $view_id = intval($atts['viewid']); $results = get_view_query_results( $view_id ); return count($results); }
Use the shortcode - replace 123 with the View ID of your choice:
[ts_view_has_results viewid="123"]
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/
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 4 replies, has 2 voices.
Last updated by 7 years, 6 months ago.
Assisted by: Christian Cox.