I think you made a mistake again.
I need two things.
- See parents that doesn't have chiild
- See childs that doens't have parent
You create first fonction for my first needs : func_check_post_has_child
But that does't work.
I create a page : hidden link
I create view : hidden link
And my code below.
And the view sho all parents with child and not parent without child.
I don't understand the code, so i can say if you have made mistake or if it doesn't work.
The strange thing is the name of your function : func_check_post_has_child
I will name it func_check_post_has_not_child
Thanks a lot for your help.
----
//on récupère les programmes sans lot
function func_check_post_has_child( $query, $view_settings, $view_id ){
$relationship = 'programme-lot'; // Edit for relationship slug
if ( in_array( $view_id, array( 24385) ) && !empty( $query->posts ) ){
foreach ($query->posts as $key => $parent) {
// get the child posts of the parent post
$children = toolset_get_related_posts(
$parent->ID,
$relationship,
array(
'query_by_role' => 'parent',
'role_to_return' => 'child'
)
);
$number_of_children = count( $children );
if ( $number_of_children !== 0 ) {
}else{
unset( $query->posts[$key] );
$query->found_posts = $query->found_posts - 1;
$query->post_count = $query->post_count - 1;
}
}
$query->posts = array_values( $query->posts );
}
return $query;
}
add_filter( 'wpv_filter_query_post_process', 'func_check_post_has_child', 1001, 3 );