• Resolved jnasoy

    (@jnasoy)


    Hello,

    Is there a way to query all the posts that the current logged-in user rated?

    Thank you

    • This topic was modified 4 years, 5 months ago by jnasoy.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jnasoy

    (@jnasoy)

    Here’s my initial solution.

    I just grabbed all the reviews using glsr_get_reviews function and setup a condition that if user_id == current_loggedin_user_id, saved the assigned_to IDs in an array and use it in post__in to query the posts. This requires more than one queries, which I don’t really care that much but does anyone know a more efficient way to do it?

    Thank you

    • This reply was modified 4 years, 5 months ago by jnasoy.
    Plugin Author Gemini Labs

    (@geminilabs)

    The Site Reviews > Help Functions page shows how to query all reviews submitted by the logged in user:

    Plugin Author Gemini Labs

    (@geminilabs)

    You could also do this:

    
    global $wpdb;
    
    // This is a super fast raw database query that returns an array of Post IDs
    // that have been assigned to reviews submitted by the current user.
    $postIds = $wpdb->get_col($wpdb->prepare("
      SELECT DISTINCT ap.post_id
      FROM {$wpdb->prefix}glsr_assigned_posts AS ap
      INNER JOIN {$wpdb->prefix}glsr_ratings AS r ON ap.rating_id = r.ID
      WHERE r.review_id IN(
        SELECT ids.* FROM (
          SELECT ID FROM {$wpdb->posts}
          WHERE post_status = 'publish' AND post_author = %d
        ) AS ids
      )
    ", get_current_user_id()));
    
    $query = new WP_Query([
        'post__in' => $postIds,
    ]);
    
    • This reply was modified 4 years, 5 months ago by Gemini Labs.
    • This reply was modified 4 years, 5 months ago by Gemini Labs.
    • This reply was modified 4 years, 5 months ago by Gemini Labs.
    Thread Starter jnasoy

    (@jnasoy)

    Thank you so much for the response. I will try the options

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get All Posts Reviews By Certain User’ is closed to new replies.