I am trying to: Display with a view a list of parents. The sorting depends on the presence of a chld post.
I visited this URL: https://toolset.com/forums/topic/how-to-display-a-list-of-all-parents-and-sorting-if-there-is-a-child-yes-or-no/
This works:
[wpv-conditional if="( '[has_children_of_type post_type="testimonial" ]' eq '1' )"]
*** content ***
[/wpv-conditional]
But I'm looking for something that looks like, so it displays first the items with a child-post and below this, the items without a chil-post:
[wpv-conditional if="( '[has_children_of_type post_type="testimonial" ]' eq '1' )"]
display content
[/wpv-conditional]
[wpv-conditional if="( '[has_children_of_type post_type="testimonial" ]' ne '1' )"]
display content
[/wpv-conditional]
Where do I place this coding?
**** loop output ***
[wpv-layout-start]
[wpv-items-found]
Aantal campers: [wpv-found-count]
[wpv-pager-prev-page][wpml-string context="wpv-views"]Vorige[/wpml-string][/wpv-pager-prev-page][wpv-pager-nav-links ul_class="wpv_pagination_dots" li_class="wpv_pagination_dots_item" current_type="link"][wpv-pager-next-page][wpml-string context="wpv-views"]Volgende[/wpml-string][/wpv-pager-next-page]
<!-- wpv-loop-start -->
<table class="c_result">
<thead>
<th colspan="3">
***
</th>
</thead>
<tbody>
<wpv-loop>
<tr>
[wpv-post-body view_template="Loop item in XXX overzicht"]
</tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[wpv-pager-prev-page][wpml-string context="wpv-views"]Vorige[/wpml-string][/wpv-pager-prev-page][wpv-pager-nav-links ul_class="wpv_pagination_dots" li_class="wpv_pagination_dots_item" current_type="link"][wpv-pager-next-page][wpml-string context="wpv-views"]Volgende[/wpml-string][/wpv-pager-next-page]
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]Geen XXX gevonden[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
**** end loop output ****
Dear mcj,
Unfortunately, there isn't such a build-in feature within Views.
And the answer of Ross:
https://toolset.com/forums/topic/how-to-display-a-list-of-all-parents-and-sorting-if-there-is-a-child-yes-or-no/#post-364172
only works for display the item which has child room posts, it can not re-order the results.
In your case, I suggest you try to create custom Views filter hook wpv_filter_query_post_process,:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query_post_process/
In your custom function, get the count of child "testimonial" posts of current posts, use PHP function to resort the results:
hidden link
But it won't work when you use Views pagination, just for your reference.
tnx for the answer, I will think about another solution.