I am trying to: Sorting my view (Parent=House) , not on the contents of a parent field , but depending on whether there is or there is not a child (Room) present ?
For example:
House1 Room1
House2
House3 Room3
House4 Room4
House5
The list I want to create I would like to display looks then:
House1 Room1
House3 Room3
House4 Room4
House2 <- has no childeren, so display this one after the parents with children.
House5 <- has no children
I don't know how to do this?
Thank you for contacting Toolset support, I'd be delighted to assist!
To query if a parent object has children, you would need a custom shortcode such as:
function has_children_of_type( $atts ) {
global $post;
extract( shortcode_atts( array(
'post_type' => 'TYPE', // Make sure to set the correct post type
), $atts ) );
$parent_type = $post->post_type;
$childargs = array(
'post_type' => $post_type,
'numberposts' => -1,
'meta_query' => array( array( 'key' => '_wpcf_belongs_'.$parent_type.'_id', 'value' => $post->ID ) )
);
$child_posts = get_posts( $childargs );
return count( $child_posts ) == 0 ? false : true;
}
add_shortcode( 'has_children_of_type', 'has_children_of_type' );
Then go to Views > Settings > Compatibility > Third-party shortcode arguments and add the shortcode.
You can then use it in your views using something like the following:
[wpv-conditional if="( '[has_children_of_type post_type="testimonial" ]' eq '1' )"]
CONTENT
[/wpv-conditional]
If needed, you can nest views within views as well: https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
Excuses for delay, but now I have other problems with my website.
So I don't have time to follow your advice an testing it.
I will close this thread , read your instructions and when I have questions again, I will make a new thread.