Problem: I have a View that shows posts and custom field values from those posts. The View is sorted by the custom field. If one of the results in the View does not contain a value for that custom field, it is not included in the search results.
Solution: This is the result of a quirk in WordPress queries. When sorting by a custom field, posts that do not contain a value for that custom field are not included in the search results. There are two workarounds:
1. Give every post a death date value. Choose the same date like January 1, 1700, for each post that does not have a death date. Use conditional HTML to hide January 1, 1700 on the front-end of the site and display something different like "Unknown". You can accomplish this with no extra custom code.
2. Or, create another custom field that holds a number. Copy the timestamp from the death date custom field into the number field when a post is saved or edited. You need custom code for this. Use the save_post hook, or cred_save_data if these posts are only added and edited by CRED. If no value is provided for the death date in a post, store a "1" in the new custom field. Sort by this number custom field, but display the death date field.
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 4 replies, has 2 voices.
Last updated by 6 years, 6 months ago.
Assisted by: Christian Cox.