Advertisement
geminilabs

[site-reviews] set the assigned_posts value from an URL parameter

Sep 6th, 2023 (edited)
1,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. /**
  2.  * Set the assigned_posts value from an URL parameter (?assigned_post=)
  3.  * Example: https://domain.com?assigned_post=4
  4.  * @param array $fields
  5.  * @return array
  6.  */
  7. add_filter('site-reviews/review-form/fields/hidden', function ($fields) {
  8.     if (!isset($fields['assigned_posts']) || !isset($fields['assigned_posts']->field)) {
  9.         return $fields;
  10.     }
  11.     if ($postId = intval(filter_input(INPUT_GET, 'assigned_post'))) {
  12.         $fields['assigned_posts']->field['value'] = $postId;
  13.     }
  14.     return $fields;
  15. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement