Advertisement
geminilabs

get all pages which have assigned reviews submitted by a specific user

Sep 24th, 2022
1,396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. global $wpdb;
  2.  
  3. $userId = 1; // change as needed
  4.  
  5. $sql = "
  6.    SELECT DISTINCT ap.post_id
  7.    FROM {$wpdb->prefix}glsr_assigned_posts ap
  8.    INNER JOIN {$wpdb->prefix}glsr_ratings r ON r.ID = ap.rating_id
  9.    INNER JOIN {$wpdb->posts} p ON p.ID = r.review_id
  10.    WHERE p.post_author = %d AND ap.is_published
  11. ";
  12.  
  13. $postIds = $wpdb->get_col($wpdb->prepare($sql, $userId));
  14.  
  15. $posts = new WP_Query([
  16.     'post__in' => $postIds,
  17.     'post_status' => 'publish',
  18.     'post_type' => 'page',
  19. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement