title: How to pass $_SESSION variables into a function
body: <p>I am trying to pass my $_SESSION variables into a database query function for WordPress. If I define the $_SESSION variables within the function it works fine. But when I define them on a global level and try to pass them in, they do not pass through. Please view below for examples.</p>
  
  <p>This will pass through to the function below</p>
  
  <pre><code>$_SESSION['pages'] = $_POST['pages'];
  </code></pre>
  
  <p>But when I add</p>
  
  <pre><code>$pages = $_SESSION['pages'];
  </code></pre>
  
  <p>$pages will not pass through to the function.</p>
  
  <pre><code>    $_SESSION['pages'] = $_POST['pages']; //passes
      $pages = $_SESSION['pages']; //does not pass
  
  function insertLocalBusinessSchema()
      {
          //include global config  
          include_once($_SERVER['DOCUMENT_ROOT'].'/stage/wp-config.php' );
  
          global $wpdb;
  
          // if I try to define this outside of the function it doesn't pass through.
          $pages = implode(',', $_SESSION['pages']);
  
          $paymentAccepted = implode(',', $_SESSION['paymentAccepted']);
  
          $table_name = $wpdb-&gt;prefix . "schemaLocalBusiness";
  
          $insert = "UPDATE ".$table_name." SET addressLocality = '".$_SESSION['addressLocality']."', addressRegion = '".$_SESSION['addressRegion']."', postalCode = '".$_SESSION['postalCode']."', streetAddress = '".$_SESSION['streetAddress']."', pages = '".$pages."', paymentAccepted = '".$paymentAccepted."' WHERE id = 1";
  
          $wpdb-&gt;query($insert);
  
      }
  </code></pre>
  
  <p>Thank you for the help in advance! </p>