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!
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.