Advertisement
bedas

New Query - works

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