I am trying to:
Make custom prev/next entries based on a number stored in a custom field.
Some of the numbers are identical--in this case 'previous' should sort by Post Title, desc. order. 'next' would sort by asc. order.
Link to a page where the issue can be seen:
I expected to see:
My next links sort by descending/ascending post title, as when I list all entries in a different View I have created.
Instead, I got:
A loop. Post 'A' has a custom value of 100000. Post B has the same. A Post 'C' has a value of 75000. When clicking the link, I will get A->B->A with each click. This problem does not occur when the values are different.
Possible fix I have tried and various, similar attemps (previous entry, in this case):
Sort primary by Post title. Then I cannot choose the secondary sorting by custom field. So I tried it with filters (less than or equal).
Also tried to skip an entry, including or excluding the current entry. Same result.
It seems that an "equal or less than" rather than "less than or equal" may be the logic I may need, but it's not available.
I am passing the current page's custom field value with a shortcode parameter for the filter comparison.
I've also passed the current post ID, and excluded it (this doesn't seem to help one way or the other, however).
Okay it looks like you want to place this View on a single post and use it to allow your site visitors to navigate from post to post in order of hotness, secondarily ordered by post title. The main problem I see here is that there is no effective way to pass the current post's corresponding page number into the View. This means the pagination system has no context to determine where the current post lives in relation to other posts with the same Scoville number field value, when the View is placed on a single post. If the View is placed on a custom search page, then the pagination system will always know which page number is currently being displayed and the problem does not occur.
What you would need to know is the page numbers of the sorted View that correspond to the next and previous posts, in the context of a single post. That's not easy to determine, and will require custom code. One possible way to get around this is to create a second custom field that stores a more precise number than the Scoville number, and use that value for sorting and filtering. For example, if there are 5 posts with a Scoville number of 1000000, then the new custom field values for those posts would be:
1000000
1000001
1000002
1000003
1000004
You will apply those values in wp-admin based on the post titles. If you're adding and removing posts frequently this might not be a practical solution. Let me know your thoughts and we can go from there.
Understood. Thanks for the clear answer!
Currently, our hack is to use built-in prev/next articles and their relationship is determined by the post date. We order them manually by setting up dates in the past that aren't viewed in the front-end.
The additional field for sorting should work--I understand that. But it doesn't make it any easier on us.
Is there a way to create a view that grabs multiple entries that include the secondary sorting so Views knows what is next alphabetically, but hide those results from the user? Would that be a solution?
Even nicer would be a "Toolset cool-guy way" to get an individual next/prev result based on a custom field.... but that would be a feature request. Any chance to get that on the roadmap?
Thanks again!
Is there a way to create a view that grabs multiple entries that include the secondary sorting so Views knows what is next alphabetically, but hide those results from the user? Would that be a solution?
You can definitely create this type of View. The problem is that when you place the View on a single post, there is no way to tell the View which "page" of results corresponds to the current single post. There is no method of communication between the current post and the View that can establish this context. So you would have to use custom JavaScript or some other method to determine which of the results in the View corresponds to the current post, then manipulate the DOM to set the correct next and previous link URLs based on those hidden results.
Even nicer would be a "Toolset cool-guy way" to get an individual next/prev result based on a custom field.... but that would be a feature request. Any chance to get that on the roadmap?
If I understand you correctly, you can do this now. Create two custom fields on the post, one for next and one for previous. Add the post ID of the next and previous posts to these custom fields. Then use the wpv-post-url shortcode with the wpv-post-field shortcode to display links to the next and previous posts in the single post template. This seems even more complicated to maintain than the other solution I mentioned before, which is one additional custom field with a precise sort order number.