Robert Granlund
asked on
Session Variables in Wordpress
I'm trying to create session variables in Wordpress and have discovered that Wordpress does not really do this. I found a plugin Called WP_Sessions and it is said to help create sessions. How you use it is as follows:
OK, I want to store a field from a form.
Here is a link to the plugin:
https://wordpress.org/plugins/wp-session-manager/faq/
$wp_session = WP_Session::get_instance();
$wp_session['user_name'] = 'User Name'; // A string
$wp_session['user_contact'] = array( 'email' => 'user@name.com' ); // An array
$wp_session['user_obj'] = new WP_User( 1 ); // An objec
OK, I want to store a field from a form.
<input type="text" name="addon-28-bicycle-info[manufacturer]" id="addon-28-bicycle-info[manufacturer]" value="<?php if(isset($_POST['addon-28-bicycle-info']['manufacturer'])) {echo $_POST['addon-28-bicycle-info']['manufacturer'];} ?>" >
How do I store that field as a session variable after the form is submitted?Here is a link to the plugin:
https://wordpress.org/plugins/wp-session-manager/faq/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes
ASKER
Do those need to be in the head?
The head of what? PHP code is independent of HTML structures. Traditionally, we have constructed PHP pages like so:
But there's no difference between that and this:
So long as the variables are declared before they are used, you should be okay.
<?php
blah;
blah;
blah;
?>
<html>
<head></head>
<body>
<?php echo $somevar ?>
</body>
</html>
But there's no difference between that and this:
<html>
<head></head>
<body>
<?php
blah;
blah;
blah;
echo $somevar;
?>
</body>
</html>
So long as the variables are declared before they are used, you should be okay.
ASKER
$_SESSION['bv'] = $_POST['bike_value'];
$_SESSION['manu'] = $_POST['addon-28-bicycle-i