Skip Navigation

[Resolved] Customizing display of post meta item values with for_each

This support ticket is created 3 years, 6 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 3 voices.

Last updated by Don 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2090293

Don

Tell us what you are trying to do?

I have a type custom field which allows multiple (numeric) values for a post type. In the archive view for that post type, and in the single post template, I want to display these multiple values as a RANGE, IF there are indeed more than one value stored for that post, based on the numerical value of each item, rather than showing ALL values... OR rather than using start="1" and end="x?" since the values wont necessarily be entered in numerical order. Is there a way to do this? In the attributes for a for_each i only see a start and end option, which i assume will only operate on the order that the values were entered/saved. Is there something I can do before the for_each is called, to basically "sort" these numerical values and display only the lowest "(new first item value)" and, if more than one item value for that field, with "-(last item value)"?

I feel like i am getting sooooooo close to having my fields how i need them, for creating a post and the display of values, but i really need to be able to display these multiple item values for a types custom field as a min-max range somehow.....

#2090447

Nigel
Supporter

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

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

It's not possible to implement this using the plugin UI, it's essentially a custom feature that would need implementing using a custom shortcode.

That shortcode would need to get all of the values of the custom field for the current post, return the only value if there is just one value, otherwise order the values and return a string constructed from the first value hyphen and the last (highest) value.

You would register a custom shortcode with add_shortcode (https://developer.wordpress.org/reference/functions/add_shortcode/), and you can read more about them here: https://developer.wordpress.org/plugins/shortcodes/

You could then insert the shortcode using a core Shortcode block.

#2090879

Don

ok thanks for clarifying that getting the lowest and highest numerical values of a multiple value custom field is not possible as is with the for_each or a conditional before it somehow.... will hopefully be able to figure out how to create a custom shortcode to get it, from looks of it would have to do sort meta_values for a specified meta_key associated with the current post_id correct?

Might be something worth considering adding in to the for_each arsenal, i see for other things in the shortcode section you can filter by even or odd, first, last, etc.... and i can imagine being able to filter/sort/display based on lowest or highest for numerical values would be useful to others too....

#2091195

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

ok thanks for clarifying that getting the lowest and highest numerical values of a multiple value custom field is not possible as is with the for_each or a conditional before it somehow.... will hopefully be able to figure out how to create a custom shortcode to get it, from looks of it would have to do sort meta_values for a specified meta_key associated with the current post_id correct?
==>
Yes, thats correct.

Might be something worth considering adding in to the for_each arsenal, i see for other things in the shortcode section you can filter by even or odd, first, last, etc.... and i can imagine being able to filter/sort/display based on lowest or highest for numerical values would be useful to others too....
==>
You are welcome to file a new feature request using the following link and our product manager will review it:
- https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#2091275

Don

My issue is not resolved but thanks anyways for the clarifications and suggestions. Thank you!