I have a setup that uses one View nested within another. The first view fetches all of the Films posts within a certain taxonomy. Then, within that loop, for each Film Post a View is used to pull event posts from The Event Calendar plugin that are children of that Film Post and display those chronolgically according to the event start date field.
However, the event posts are not ordering correctly. I cannot tell how they are being ordered. It is neither chronological nor by menu order. It seems random.
I should note that in I use another View for a different page that displays these same children Event Calendar Posts on their own, not nested within another View. In that instance, they do display correctly, so I know it is not a problem with the posts themselves.
Link to a page where the issue can be seen: hidden link
Hello. Thank you for contacting the Toolset support.
I see you are using Events calendar plugin. I would like to know here are you trying to sort by Events calendar date that is coming from events calendar? If yes, events calendar dates are stores as date string and we need to apply view's hook in order to sort the event calendar date in the correct order.
If able information is correct, can I have problem URL where you are displaying the events and access details?
I have set the next reply to private which means only you and I have access to it.
Parent post 1
-- child post 1- date - 23-04-2017
-- child post 2- date - 25-05-2017
-- child post 3- date - 23-06-2017
Parent post 2
-- child post 4- date - 27-04-2017
-- child post 5- date - 2-04-2017
-- child post 6- date - 23-06-2017
Parent post 3
-- child post 7-date - 23-09-2017
-- child post 8- date - 25-11-2017
-- child post 9- date - 23-12-2017
Lets consider the above structure, as you added the child view to your parent view, with each parent view loop it will call the child view and the order will be followed of parent view. Do you only want to sort the child view posts?
No, I need to sort the parent view by the title and the child view by the date field. However, if this is not possible, I can work around this if I know how the child view is being sorted. For example, if the child view is being sorted by title because the parent view is being sorted by title, then I can adjust the child post titles accordingly. But I do not know how the child posts are being sorted, if they are being sorted at all.
You can set the sorting option for your parent or child post view when you edit your parent/child view from the ordering section.
The thing is that parent view will query posts belongs to your parent post type and child view will query the posts belongs to your child post type. Child view sorting order will not have an effect on your parent view's sorting order. Having said that you can not sort the child view by parent view's sort order because both view will query different post types.
I found the following code is added to your theme's functions.php file and the child view order is affected by the order you set using the following code:
// Sorts by temp column
function wpcf_sort_by_temp_column ($orderby) {
$custom_orderby = "UPPER(title2) ASC";
if ($custom_orderby) {
$orderby = $custom_orderby;
}
return $orderby;
}
I do not know if the above code you added should be applied to your child view that displays the event dates.
That code is for sorting the title alphabetically without preceding articles (A, And, The). I see by removing it that it is also overriding any sorting parameters on the child view. I will have to find another way of sorting the titles then.