Skip Navigation

[Closed] Maximum and minimum price via views

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 2 years, 10 months ago.

Author
Posts
#2294143

I have a views that shows items with a price. I would like to create a shortcode in toolset to retrieve the maximum and minimum price of the filtered items and show them in a text

#2294465

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Your View outputs a series of posts (which may have been filtered), and you want to display the the max and min prices from just those posts, yes?

This is a bit tricky and requires more than a simple shortcode.

I imagine two ways you may do this; choose whichever you are most comfortable with (and if you are not comfortable with either, you will need to recruit a developer to code this for you).

The first is to create two shortcodes.

One is added inside the loop. It doesn't output anything itself, but it uses static variables to keep track which is the min and max price so far (comparing the existing min and max with the current prices and updating where necessary).

When you get to the end of the loop those static variables will contain the min and max prices for all the posts iterated over.

You then have a second shortcode (or two separate shortcodes) which use this static value for min and for max and return them as strings. You would add the shortcode(s) after the closing /wpv-loop element but before the closing /wpv-items-found shortcode.

If you needed the prices to appear somewhere else, it may be possible (I'm not sure, I haven't tested it) to use the wpv_filter_query_post_process hook (which is triggered after the View query has been run but before the results are output) to loop over the results, get the prices, calculate the min and max, and then register some shortcode which simply outputs those min and max values. Include the shortcode itself in the output section of the View where you want it to appear.

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

Please note this is quite a bespoke request, you will need to code it yourself, it's not something we can do for you.

The topic ‘[Closed] Maximum and minimum price via views’ is closed to new replies.