Skip Navigation

[Resolved] View – sort custom field with a specific order

This thread is resolved. Here is a description of the problem and solution.

Problem:

The customer asked how to order the results in the view based on the custom field having values like Platinum, Diamond, Gold, etc.

Solution:

Recommend adding the custom field as a select type field, where the options (e.g. Platinum, Diamond, Gold, Silver, etc) have the numeric values in the required order (e.g. 1, 2, 3, 4, etc).

This will allow selecting this field in the view's "Ordering" settings and the results will be ordered, accordingly.

Relevant Documentation:

n/a

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
- 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 4 replies, has 2 voices.

Last updated by philippeS-4 1 year, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2409727

I am trying to build a view to list sponsors for an event, the order should be based on the sponsor type custom field and should follow that specific order Platinum, Diamond, Gold, ....

I currently have built an individual view for each sponsor type and this works well - see example: hidden link but the looks is not great since I have a new row for each sponsor type.

I have just built a new view as I would like it see - hidden link now I just need to be able to sort based on the Sponsor Type with the specific order mentionned above. The easiest way would be to create an extra custom field for the sort order, but seems a bit cumbersome. Just wondering if there is a better way?

Thanks,
Phil

#2410717

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

select-field-example.png

Hi Phil,

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

To achieve this order using a single view, I'd recommend adding the "Sponsor Type" field as a select type field, where the options (e.g. Platinum, Diamond, Gold, Silver, etc) have the numeric values in the required order (e.g. 1, 2, 3, 4, etc).
( example screenshot attached )

This way, you'll be able to select this field in the view's "Ordering" settings and the results will be ordered, accordingly.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2410947

Hi Waqar,

Thanks for your detailed reply. So the display value will be returned when I use the select type custom field. But the ordering or any conditional I do will be based on the custom field value.

As you can see in this example I use the value of the sponsor type as part of the CSS class. Can you confirm that in this case it will return the display text and not the custom field value

Thanks,
Phil

 <div class="logobox [types field='sponsortype'][/types]">
		<a data-fancybox data-src="#myModal-[wpv-post-id]" href="javascript:;">[types field='exhibitor-logo'][/types]</a>
         <div class="label-[types field='sponsortype'][/types]"> <h6>[types field='sponsortype'][/types]</h6></div>                                                                      
      </div>
#2410985

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

Yes, that is correct. The types shortcode for the select field will return the option's "text" and not the raw custom field value, for example:
https://toolset.com/documentation/customizing-sites-using-php/functions/#select


[types field='sponsortype'][/types]

To get the raw custom field value, you'll need to include output='raw', for example:


[types field='sponsortype' output='raw'][/types]

#2410987

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.