Advertisement
maxworkingwell

show only items without relationship

Aug 25th, 2022
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. // show only items without relationship
  2. function func_check_item_has_child( $query, $view_settings, $view_id ){
  3.        
  4.     if ( in_array( $view_id, array( 70693) ) && !empty( $query->posts ) ){
  5.      $all_posts = $query->posts;
  6.         foreach ($query->posts as $key => $parent) {
  7.      
  8.             // get the child posts of the parent post
  9.             $children = toolset_get_related_posts(
  10.                 $parent->ID,
  11.                 'related-' .$parent->post_type,
  12.                 'parent',
  13.                  1,
  14.                  0,
  15.                  array(),
  16.                  'post_id',
  17.                  'child'
  18.             );
  19.              
  20.                  
  21.             if ( !empty($children) ) {
  22.                      
  23.                 unset( $query->posts[$key] );
  24.                 $query->found_posts = $query->found_posts - 1;
  25.                 $query->post_count = $query->post_count - 1;
  26.                  
  27.             }
  28.            
  29.      
  30.         }
  31.      
  32.         $query->posts = array_values( $query->posts );
  33.     }
  34.      
  35.     return $query;
  36. }
  37. add_filter( 'wpv_filter_query_post_process', 'func_check_item_has_child', 1001, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement