Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function custom_filter_wpf_user_can_access($posts, $query) {
- // Check if we are on the main query and the user is logged in
- if (is_main_query() && is_user_logged_in()) {
- // Array to hold accessible and inaccessible posts
- $accessible_posts = array();
- $inaccessible_posts = array();
- // Loop through each post and check if the user can access it
- foreach ($posts as $post) {
- // Check if the user can access the post
- if (wpf_user_can_access($post->ID)) {
- // If accessible, add it to the accessible_posts array
- $accessible_posts[] = $post;
- } else {
- // If inaccessible, add it to the inaccessible_posts array
- $inaccessible_posts[] = $post;
- }
- }
- // Concatenate the accessible_posts and inaccessible_posts arrays to reorder the $posts array
- $posts = array_merge($accessible_posts, $inaccessible_posts);
- }
- return $posts;
- }
- add_filter('the_posts', 'custom_filter_wpf_user_can_access', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement