Skip Navigation

[Resolved] Parametric search removes items with no value when sorting

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

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 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#531027

I have a channel lineup that uses parametric search:

hidden link

Certain channels have an HD version, and some do not. When I sort by the HD channel, all of the channels that have no value for HD are actually removed from the list, instead of keeping them there, but moving them to the top or bottom.

Is there a way to fix this?

Thanks!

#531092

Hi, the easy way to handle this is like you have already done - place some value in the custom field. In your View, you can use conditional output to show the field unless it contains your placeholder value:

<td>[wpv-conditional if="( $(wpcf-slug) ne '*' )"][types field='slug'][/types][/wpv-conditional]</td>

In this example my custom field has the slug "slug", but yours will be different.

A more complex approach is possible if you would prefer not to use an asterisk or other mark, but it requires some custom code. Here's the general idea:
- Create another custom field for your posts. This field will essentially be a clone of your current HD field, but will never include an empty value.
- Whenever posts are saved, update the new HD custom field using the WordPress "save_post" hook. If no value is present in the old HD field when the post is saved, apply some placeholder value to your new HD field, like "*" or "ZZZZZ" depending on how you want them to sort. If a value is present in the old custom field, copy that value to the new custom field.
- In your View, include your new custom field so that header sorting works correctly. Use the "wpv-post-field-meta-{$name}" filter to replace the placeholder value with an empty string.

Some useful information about these filters:
- https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv-post-field-meta-name

If you have specific questions about implementation, I'll be glad to help - I'm just not sure if this is even an option you'd like to consider. Let me know your thoughts.

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