Problem: I would like to show the largest numeric value from a custom field applied to my custom post type.
Solution: One way to do this in Toolset is to create a View of all Books, ordered by your custom field "price" (descending), and limited to 1 result. In the Loop Output you could use the wpv-post-field shortcode to output the value of your price custom field. Then apply the raw text filter to strip out the extra markup, and the View will return the value of the highest custom field. If you don't have that raw text filter, I'll include it here:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 ); function prefix_clean_view_output( $out, $id ) { $ids = array( 1, 2, 3, 4 ); if ( in_array( $id, $ids ) ) { $start = strpos( $out, '<!-- wpv-loop-start -->' ); if ( $start !== false && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false ) { $start = $start + strlen( '<!-- wpv-loop-start -->' ); $out = substr( $out , $start ); $end = strrpos( $out, '<!-- wpv-loop-end -->' ); $out = substr( $out, 0, $end ); } else { $start = strpos( $out, '>' ); if ( $start !== false) { $out = substr( $out, $start + 1 ); $end = strpos( $out, '<' ); $out = trim(substr( $out, 0, $end )); } } } return $out; }
Modify $ids to include a comma-separated list of the numeric IDs of any View you would like to filter to output the raw Loop Output with no extra markup.
Finally, you may need to disable "Don't include current page in query result" in the View editor.
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, 1 month ago.
Assisted by: Christian Cox.