Comments from UI
-
Are you talking about WordPress comments, or the review response that you can add to a review when editing it in the admin?
You can get the Post ID of the review in the template like this:
$postId = $review->ID; // OR with an extra check to make sure the $review object exists $postId = isset($review) ? $review->ID : 0; // OR using the glsr_get() helper function (using the safe apply_filters method) // Arguments are explained like this: // 1. function name // 2. arg1 = value to use if the plugin is not installed // 3. arg2 = object/array to search // 4. arg3 = object/array key to get the value from // 5. arg4 = value to return if the object/array key does not exist $postId = apply_filters('glsr_get', 0, $review, 'ID', 0);Thank you very much 🙂
I have one more question…
I made this code. When an admin is logged in, there will be an input box to response to a review. How can I save the response into the database, when the form is submitted?<?php $current_user = wp_get_current_user(); if (user_can( $current_user, 'administrator' )) { ?> <form autocomplete="off" action="/post-comment.php" method="post"> <div> <input type="hidden" id="reviewid" name="reviewid" value=<?= $postId = $review->ID; ?> readonly> <input type="text" id="comment" name="comment" placeholder="Indtast dit svar til overstående review"> </div> <input type="submit" value="Indsend"> </form> <?php } ?>-
This reply was modified 5 years, 10 months ago by
digitali17.
The response is saved as post meta of the review (using the
_responsemeta_key).For example, this is what Site Reviews does:
$allowedHtml = [ 'a' => [ 'href' => [], 'title' => [], ], 'em' => [], 'strong' => [], ]; $response = trim(wp_kses($responseText, $allowedHtml)); update_post_meta($postId, '_response', $response);How can I implement that in my example?
Use that in whichever function you use to handle your form submission. Since you are submitting your form to
/post-comment.php, that’s probably where you would use it. -
This reply was modified 5 years, 10 months ago by
The topic ‘Comments from UI’ is closed to new replies.
(@digitali17)
5 years, 10 months ago
Hi
I’m trying to modify the plugin so you can add comments to a review direct from the page (instead of the admin panel).
I have added a comment section in the file templates/review.php. Now I need to get the review ID so I can link a comment to the review, when the user submit.
How can I get the ID?