Advertisement
geminilabs

Untitled

Nov 29th, 2022
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. /**
  2.  * Set the Assigned Posts dropdown value from an URL parameter (?product_id=1)
  3.  * Example: https://domain.com?product_id=26904
  4.  * @param array $fields
  5.  * @return array
  6.  */
  7. add_filter('site-reviews/review-form/fields/normalized', function ($fields) {
  8.     foreach ($fields as $field) {
  9.         if ('assigned_posts' !== glsr_get($field, 'field.type')) {
  10.             continue;
  11.         }
  12.         if (!in_array('product', glsr_get($field, 'field.posttypes'))) {
  13.             continue;
  14.         }
  15.         $postId = intval(filter_input(INPUT_GET, 'product_id'));
  16.         if (empty($postId) || 'product' !== get_post_type($postId)) {
  17.             continue;
  18.         }
  19.         $field->field['value'] = $postId;
  20.         break;
  21.     }
  22.     return $fields;
  23. }, 20);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement