Skip Navigation

[Resolved] How to display a list of all parents and sorting if there is a child (2)?

This support ticket is created 8 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by mcjS 8 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#369922

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 ****

#370051

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.

#370061

tnx for the answer, I will think about another solution.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.