0

I am building a reviewing system for user-submitted posts on my website. I have a page called page-review.php which displays the oldest post of the "pending review" category. This is to ensure that every user-submission gets reviewed. There is only one post displayed on this page at a time.

$review_args = array(
    'orderby' => 'post_date',
    'order' => 'ASC',
    'posts_per_page' => '1',
    'cat' => 22,
);

$review_query = new WP_Query($review_args);

After a post has been reviewed a new custom meta tag will be added to the post called reviewed_by. This meta tag contains an array of user IDs that have reviewed this post.

How do I make it so that my query checks if the custom meta reviewed_by has the current user's ID in it? And if it does find it in the reviewed_by array then it will show the next oldest post that doesn't have the user's ID in the custom meta.

UPDATE:

I still can't seem to get it working. The content in reviewed_by looks like the following (it's an array converted to a string I believe)

a:1:{i:0;i:34;}

This is an array where my user_id is 34.

$review_args = array(
    'orderby' => 'post_date',
    'order' => 'ASC',
    'posts_per_page' => '1',
    'cat' => 22,
    'meta_query' => array(
                        array(
                            'key' =>'reviewed_by',
                            'value' => $current_user_id,
                            'compare' => 'NOT IN'
                        )
                    )
);
0

According to the codex for WP_Query, you should be able to tack on some meta related arguments to your args array (this is untested):

$review_args = array(
    'orderby' => 'post_date',
    'order' => 'ASC',
    'posts_per_page' => '1',
    'cat' => 22,
    'meta_query' => array(
                        'key'=>'reviewed_by',
                        'value'=> $reviewed_by_array,
                        'compare'=> 'NOT IN'
                    )
);

$review_query = new WP_Query($review_args);
  • I have tried this with some edited code (as the code you provided wasn't complete) but I still cannot seem to get it working. I think it has to do with the 'compare' part although I am not entirely sure. I updated my question. – Swen Aug 3 '14 at 15:08
0

I ended up going with a different approach which is a lot easier. I created a new custom user_meta called review_completed. This user_meta contains an Array of the post IDs of the submissions that they have reviewed.

Then I simply added a new line to my review_args as seen below.

$user_review_completed = get_user_meta($current_user_id, 'review_completed', true);

$review_args = array(
    'orderby' => 'post_date',
    'order' => 'ASC',
    'posts_per_page' => '1',
    'cat' => 22,
    'post__not_in' => $user_review_completed
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.