I want to order a View by intermediary field, but when I do this the View returns 0 results.
I read in another support topic that this is possible if the intermediary post is set to public, which is the case for me, but nothing shows still.
I do not think this should work, as filtering by fields of related posts as well is not possible yet, but I do see the Fields of Intermediary posts in the Order by settings of Views, and I do see the same error as you do when I try to build such a View.
Hence, I am sure this is not supported yet.
Can you please link me with the thread or article where this is elaborated, so I can check there why the information was provided and if there is eventually an internal issue tracker I can follow.
I am relatively sure that option is there by mistake and should not yet figure as an option but I may be wrong, in that case, it'd be a BUG.
In any case, I reported this and we will either fix or (as I suspect) introduce this in future.
OK, I tested and confirm:
- You can order the posts that you currently query by their fields.
- You cannot query posts by fields of other posts that are not in the query or where that field is not added to
- But, unfortunately, you can still set them to order your output in Views, even if you query a Post Type that has no such field attached.
And that will always result in a "No results found"
So, if you want to Order posts you have to:
- Content Selection ==> The Post type where the field is assigned (and populated)
- Ordering ==> The Field of choice must be attached and populated in the queried Post Type
So, to order Posts by Fields of Intermediary Posts, you must query Intermediary Posts (and make sure those fields are populated)
The problem is sole that we provide the ordering by those fields even if you do not query the related post type, I reported that and we will fix it.
In a future release Toolset Views will allow to Query by Related Posts Fields and with that we will as well open the doors to Ordering by related fields
Thanks for the help so far Beda.
These are the two threads I was referencing.
https://toolset.com/forums/topic/filter-and-or-sort-by-custom-field-in-m2m-relationship/
https://toolset.com/forums/topic/unable-to-use-intermediary-post-type-as-a-sort-by/
So to achieve what I want I understand that I must do the following.
Content Selection must be the intermediary post type that I want to order the view by a field of?
When I look to create a View, i cannot see any intermediary post types visible for selection.
I managed to make intermediary post types available for content selection by visiting them in the Toolset dashboard and saving them.
This lets me order by the intermediary post type field, but i need to do this whilst displaying the data from another post type.
However, I think I may have found a way to accomplish what I need.
If I set up a View and set Content Selection to the intermediary post type. I can then order the View by the intermediary post type field.
Then I can edit the loop to display the fields of related data from the post type that i originally had in the Content Selection.