Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Set the Assigned Posts dropdown value from an URL parameter (?product_id=1)
- * Example: https://domain.com?product_id=26904
- * @param array $fields
- * @return array
- */
- add_filter('site-reviews/review-form/fields/normalized', function ($fields) {
- foreach ($fields as $field) {
- if ('assigned_posts' !== glsr_get($field, 'field.type')) {
- continue;
- }
- if (!in_array('product', glsr_get($field, 'field.posttypes'))) {
- continue;
- }
- $postId = intval(filter_input(INPUT_GET, 'product_id'));
- if (empty($postId) || 'product' !== get_post_type($postId)) {
- continue;
- }
- $field->field['value'] = $postId;
- break;
- }
- return $fields;
- }, 20);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement