admin管理员组

文章数量:1312985

I have a Custom Post Type (CPT) and I want to have a Review system for this post type. I could not find any plugin which support reviews for the posts so I am thinking to do this with my own coding. But I want some guidelines for this so people can leave review for each of the post with their image, name, email and comment.

I am using default comments for my blog posts so I think for these I will need to create a separate comment like system.

I have a Custom Post Type (CPT) and I want to have a Review system for this post type. I could not find any plugin which support reviews for the posts so I am thinking to do this with my own coding. But I want some guidelines for this so people can leave review for each of the post with their image, name, email and comment.

I am using default comments for my blog posts so I think for these I will need to create a separate comment like system.

Share Improve this question edited May 11, 2020 at 6:57 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked May 10, 2020 at 15:31 wpddwpdd 3134 silver badges15 bronze badges 4
  • 1 WordPress Comment system is a kind of a review system. You can use the comment form for that. With some comment_meta fields you can let the user add their additional information (eg. image etc.) or can use any comment attachment plugin for that. So what you need first is to enable comments for your CPT. – Mayeenul Islam Commented May 10, 2020 at 18:27
  • @MayeenulIslam thank you for your time. I am using default comments for my blog posts so I think for these I will need to create a separate comment like system. Can we create a custom comment type like we create custom post types. – wpdd Commented May 10, 2020 at 19:37
  • 1 Then you are well-advanced. :) You can use custom comment type and can build different form and can store additional information in comment_meta. What's actually stopping you? – Mayeenul Islam Commented May 10, 2020 at 21:22
  • @MayeenulIslam I do not know how to create a custom comment type. Is there any function like register_post_type() to create a custom comment type – wpdd Commented May 11, 2020 at 0:20
Add a comment  | 

1 Answer 1

Reset to default 1

As you are using the default commenting feature for commenting, you can do all on your own. A rough idea on how to do that could be like below:

Step 1: Create Form and Display

Create your own form and enqueue on your post template

// Clear up the alert parameters.
$_SERVER['REQUEST_URI'] = remove_query_arg( 'success', $_SERVER['REQUEST_URI'] );

<form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>">
    <label for="review-content"><?php _e( 'Your Review' ); ?></label>
    <textarea name="review_content" id="review-content" cols="30" rows="4"></textarea>

    <?php wp_nonce_field( 'my-review-nonce' ); ?>

    <button type="submit" name="my_review_form"><?php _e( 'Save' ); ?></button>
</form>

Step 2: Grab Form Data

Intercept the form submission and sanitize input fields

Step 3: Insert Comment with meta data

本文标签: hooksHow to build a WordPress post review system beside commenting