Edit post data outside of loop [Approve/Reject system]
-
Hello everyone. I’m trying to create a PHP script that will allow my users to Approve or Reject a post. Users can click on an Approve or Reject button, which then counts the amount of approvals or rejections. Once one of the two reaches 5, it will Approve/Reject the post.
On approval it will change the post category to someone different. On rejection it will send the post to Trash.
I’m pretty sure the functions I used won’t work like this though. But I can’t figure out a way to edit a post without having the post_id in the URL. (as this would cause great security risks)
Do you guys have any idea?
My Work-In-Progress below:
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET' ) { global $post; if ( in_category(2, $post->id) ) { $approve_count = get_post_meta($post->id, 'approves'); //get the amount of approves $reject_count = get_post_meta($post->id, 'rejects'); //get the amount of rejects if ( $_GET['ar_action'] == 'approve' ) { // User clicked Approve if ($approve_count) { // Check if there already is a count $approve_count++; // Add +1 to approve_count if ($approve_count == 5) { wp_set_post_categories($post->id, 3); // Set category to "Approved" delete_post_meta($post_id->id, 'approves'); // Remove meta data because post is already approved delete_post_meta($post_id->id, 'rejects'); // Remove meta data because post is already approved } else { update_post_meta($post->id, 'approves', $approve_count); // Update approves } } else { // No approve count set add_post_meta($ar_postid, 'approves', 1); // Create approve count and set to 1 } } // End Approving if ( $_GET['ar_action'] == 'reject' ) { // User clicked Reject if ($reject_count) { // Check if there already is a count $reject_count++; // Add +1 to reject_count if ($reject_count == 5) { wp_trash_post($post->id); } else { update_post_meta($post->id, 'rejects', $reject_count); // Update rejects } } else { // No reject count set add_post_meta($ar_postid, 'rejects', 1); // Create reject count and set to 1 } } // End Rejecting } } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Edit post data outside of loop [Approve/Reject system]’ is closed to new replies.