WordPress.org

Forums

WP Session Manager
[resolved] Can't pass an array (3 posts)

  1. itailulu
    Member
    Posted 2 years ago #

    I'm trying to pass an array in $wp_session but I can't retrieve it.
    This is what I did, on page 1:

    $wp_session = WP_Session::get_instance();
    $wp_session['user_contact'] = array( 'email' => 'user@name.com' );

    Then on page 2 i tried few things:

    $data = wp_session_encode();
    print_r($data);

    and got this:
    {"user_contact":{}}

    print_r($wp_session);

    What am i doing wrong?

    Thanks!

    http://wordpress.org/extend/plugins/wp-session-manager/

  2. itailulu
    Member
    Posted 2 years ago #

    I think I got it.
    had to add:

    $session = WP_Session::get_instance();
    echo '<pre>';
    $data = $session->toArray();
    print_r($data);
    echo '</pre>';

    on page 2.

    Cool.
    Thanks for the plugin, very useful!

  3. sarankumar
    Member
    Posted 1 year ago #

    Got a solution.Updating here,may be it will help someone oneday. :

    if(isset($_POST['id']))
    		{
    		echo "<h2 id='bookingResult' > You are successfully added to your Cart </h2>"."ID=".$_POST['id'];
    		$wp_session = WP_Session::get_instance();
    
    			if(isset($wp_session['ym_cart']) && !empty($wp_session['ym_cart']))
    						{
    						$temp_array = $wp_session['ym_cart']->toArray();
    						array_push($temp_array,$_POST['id']);
    						$wp_session['ym_cart']=$temp_array;
    						}
    					else
    						{
    						$wp_session['ym_cart']= array();
    						$wp_session['ym_cart'][]=$_POST['id'];
    						}
    
    	//	print_r($wp_session['ym_cart']);
    		echo '<pre>';
    $data = $wp_session['ym_cart']->toArray();
    print_r($data);
    echo '</pre>';
    
    	    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Session Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.