Skip Navigation

[Resolved] function to get multiple instances of a custom field in the correct order

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by catherineR-2 2 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2314501

Hi,

We created a custom numeric field "some_field" attached to a custom post and allowed it to have multiple instances.

I can't find any API reference for how to fetch the instances of the field values in the correct order. I see in the database, the sort order is stored in a meta_key for the post: _wpcf-some_field-sort-order

so should we be querying the database directly, or does Toolset have a function we can call to fetch all the instances for a post_id in the correct order?

thanks

#2316001

Hi,

Thank you for contacting us and I'd be happy to assist.

Whether you'll use the Toolset Types API shortcode/function ( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/#numeric ) or the "wpv-for-each" shortcode ( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-for-each ) to get the multiple instances of a custom field, the results will be in the same order as the one shown on the post edit screen.

If you'd like those results to be in some different order, then yes, you'll need custom code to first fetch those values and then return them ordered by the desired criteria.

regards,
Waqar

#2316549

Hi,

Thanks for your reply.

It sounds like there is no types API function to just fetch the data, since the function and shortcode you mention are for fetching and also displaying.

Since we're using this field data in our custom code, we'll just query the database directly to get the order and then the meta values.

thanks,
Zubin

#2316577

My issue is resolved now. Thank you!