Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query', 10, 3 );
- function prefix_modify_empty_query( $query, $view_settings, $view_id )
- {
- if ($view_id == 41)
- {
- // get some posts (author-profile cpt)
- $args = array(
- 'posts_per_page' => -1,
- 'post_type' => 'author-profile',
- 'post_status' => 'publish',
- );
- $posts_array = new WP_Query($args);
- //If there are some posts
- if (!empty($posts_array->posts))
- {
- //build a array for valid (to return) posts
- $valid_posts = array();
- //we need to check if the posts author has the correct cap
- foreach ($posts_array->posts as $post_array)
- {
- //this custom code checks wehter the author (user) is / has capability 'pp_speaker'
- require_once( ABSPATH . 'wp-includes/pluggable.php' );
- $groups_user = new Groups_User(get_the_author_meta('ID', $post_array->post_author));
- $can_make_donuts = $groups_user->can('pp_speaker');
- if ($can_make_donuts)
- $valid_posts[] = $post_array;
- }
- }
- //If there are posts with this author / cap
- if (!empty($valid_posts))
- {
- //assign the valid posts array to the query
- $query->posts = $valid_posts;
- }
- }
- return $query;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement