Send a POST request to the reviews endpoint with the listing ID, the review text and a rating value. The GeoDirectory REST API must be on (GeoDirectory > Settings > API, “Enable the REST API”), and the request must be authenticated as the user writing the review.
The request
POST /wp-json/geodir/v2/reviews
post=123
content=Great food and friendly staff.
rating=5
postis the listing ID.contentis the review text.ratingis the overall star rating as a whole number.- Optional:
parentto reply to another review, andauthor_name/author_emailif your site requires them.
Send the values as form data or JSON in the request body. Authentication is covered in Authentication, and the full list of routes is in Endpoints.
The rating is also saved when you post to the WordPress comments route, /wp-json/wp/v2/comments, on a GeoDirectory listing, because both routes run the same rating code.
Review is saved but not visible
Reviews follow your WordPress discussion settings. If comments need approval, a review posted through the API is held as pending until you approve it under Comments in the WordPress admin. Pending reviews do not show on the listing or in recent reviews.
Listing owner gets no email
GeoDirectory sends the “new review” email to the listing owner when a comment is posted through the normal form. Comments created through the REST API skip that step. This snippet sends the same email for reviews created through the API:
add_action( 'rest_insert_comment', 'my_gd_rest_review_notify', 20, 3 );
function my_gd_rest_review_notify( $comment, $request, $creating ) {
if ( $creating && function_exists( 'geodir_new_comment_notify_postauthor' ) ) {
geodir_new_comment_notify_postauthor( $comment->comment_ID );
}
}
The email is only sent when “Email me whenever anyone posts a comment” is on at Settings > Discussion and the owner email is enabled in GeoDirectory’s email settings.