Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This snippet assumes that you have two CPT: Restaurant and Food,
- * and that you have somehow connected these two post objects (i.e. A Restaurant has many Foods).
- *
- * Since Site Reviews v4 does not allow you to assign reviews to multiple Post IDs,
- * the solution is to assign reviews to the Food CPT ID, and then have Site Reviews
- * automatically assign the reviews to a restaurant category with slug that contains
- * the Restaurant CPT Post ID. If the restaurant category does not exist, it will be
- * created when a review is submitted. This category can then be used to target all
- * food reviews for the restaurant.
- *
- * Please pay attention to the @todo in the snippet below
- *
- * If you need to manually create the restaurant categories for existing reviews,
- * the category slug must look like this: "restaurant_123" where "123" is the
- * Restaurant Post ID.
- *
- * @param \GeminiLabs\SiteReviews\Review $review
- * @return void
- */
- add_action('site-reviews/review/created', function ($review) {
- $assignedToIds = array_filter((array) $review->assigned_to);
- foreach ($assignedToIds as $foodPostId) {
- // @todo you need edit this part to get the associated restaurant post from the food post ID
- $restaurantPostId = '';
- $restaurant = get_post($restaurantPostId);
- if (empty($restaurant->ID)) {
- continue;
- }
- $termSlug = 'restaurant_'.$restaurant->ID;
- if (!term_exists($termSlug, glsr()->taxonomy)) {
- wp_insert_term($restaurant->post_title, glsr()->taxonomy, ['slug' => $termSlug]);
- }
- wp_set_object_terms($review->ID, $termSlug, glsr()->taxonomy);
- }
- });
Add Comment
Please, Sign In to add comment