Advertisement
bedas

new query

Sep 2nd, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. add_filter('wpv_filter_query', 'exclude_terms_func', 10, 3);
  2. function exclude_terms_func($query, $setting, $views_ID) {
  3.     // get some posts (author-profile cpt)
  4.     $args = array(
  5.         'posts_per_page'   => -1,
  6.         'post_type'        => 'author-profile',
  7.         'post_status'      => 'publish',
  8.     );
  9.     $posts_array = get_posts( $args );
  10.    
  11.     //If there are some posts
  12.     if ($posts_array){
  13.         //build a array for valid (to return) posts
  14.         $valid_posts = array();
  15.         //we need to check if the posts author has the correct cap
  16.         foreach ($posts_array as $post_array){
  17.  
  18.            //this custom code checks wehter the author (user) is / has capability 'pp_speaker'
  19.             require_once( ABSPATH . 'wp-includes/pluggable.php' );
  20.             $groups_user = new Groups_User( get_the_author_meta( 'ID' ) );
  21.             $can_make_donuts = $groups_user->can( 'pp_speaker' );
  22.            
  23.         }
  24.     }
  25.     //If there are posts with this author / cap
  26.     if ($can_make_donuts){
  27.  
  28.     //assign the valid posts array to the query
  29.     $query = $valid_posts;
  30.                        
  31. return $query;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement